import
java.io.*;
import
java.util.*;
public
class
main {
static
HashSet<String> allUniqueSubSeq
=
new
HashSet<>();
static
boolean
checkpower(
int
n)
{
if
((n & (n -
1
)) ==
0
) {
return
true
;
}
return
false
;
}
static
void
uniqueSubSeq(String S,
int
N, String ans,
int
index)
{
if
(index == N) {
if
(ans.length() !=
0
)
if
(checkpower(
Integer.parseInt(ans.trim()))) {
allUniqueSubSeq.add(ans);
}
return
;
}
uniqueSubSeq(S, N, ans + S.charAt(index),
index +
1
);
uniqueSubSeq(S, N, ans, index +
1
);
}
static
int
Countsubsequneces(String S,
int
N)
{
uniqueSubSeq(S, N,
""
,
0
);
return
allUniqueSubSeq.size();
}
public
static
void
main(String[] args)
{
String S =
"1216389"
;
int
N = S.length();
System.out.println(Countsubsequneces(S, N));
}
}
Original page link
Best Cool Tech Gadgets
Top favorite technology gadgets
0 comments:
Post a Comment