File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+
4
+ public class Queries {
5
+
6
+
7
+ public static void main (String [] args ) {
8
+ MyScanner scan = new MyScanner ();
9
+ PrintWriter out = new PrintWriter (new BufferedOutputStream (System .out ), true );
10
+
11
+ int N = scan .nextInt ();
12
+ for (int i = 0 ; i <N ; i ++) {
13
+ int A = scan .nextInt ();
14
+
15
+ ArrayList <Integer > subSpecial = getSubSpecialSummation (A );
16
+
17
+
18
+ for (int j = A +1 ; ; j ++) {
19
+ ArrayList <Integer > nextList = getSubSpecialSummation (j );
20
+
21
+ if (nextList .containsAll (subSpecial )) {
22
+ out .println (j );
23
+ break ;
24
+ }
25
+
26
+ }
27
+
28
+ }
29
+
30
+ out .flush ();
31
+ out .close ();
32
+
33
+
34
+ }
35
+
36
+ private static ArrayList <Integer > getSubSpecialSummation (int A ) {
37
+ int val ;
38
+ ArrayList <Integer > list = new ArrayList <>();
39
+ while (A !=0 ){
40
+ val =getPreviousPowerOfTwo (A );
41
+ A -=val ;
42
+ list .add (val );
43
+ }
44
+
45
+ return list ;
46
+ }
47
+
48
+ private static int getPreviousPowerOfTwo (int size )
49
+ {
50
+ int n = -1 ;
51
+ while (size >> ++n > 0 );
52
+ return 1 << n - 1 ;
53
+ }
54
+
55
+ }
You can’t perform that action at this time.
0 commit comments