-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathsolution.java
39 lines (35 loc) · 839 Bytes
/
solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static long two = 2;
//to get powers of 2 for demial-binary conversion
public static long getPowOf2(int i) {
if (i == 0)
return 1;
else
//left shift the bits of 2 to i-i position to take 2^i-1
return (two << (i - 1));
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(br);
int t = sc.nextInt();
//no. of test cases
while (t-- > 0)
{
long n = sc.nextLong();
long answer = 0;
for (int i = 0; i < 32; i++)
{
if (((n >> i) & 1) == 0)
{
answer = answer + getPowOf2(i);
}
}
System.out.println(answer);
}
}
}