-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathTheGreatXOR.java
More file actions
25 lines (22 loc) · 604 Bytes
/
Copy pathTheGreatXOR.java
File metadata and controls
25 lines (22 loc) · 604 Bytes
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static long theGreatXor(long x){
String s = Long.toBinaryString(x);
int l = s.length();
long ans = (long)Math.pow(2,l)-x-1;
return ans;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
for(int a0 = 0; a0 < q; a0++){
long x = in.nextLong();
long result = theGreatXor(x);
System.out.println(result);
}
}
}