글
[LuckyAlgorithm]The Great XOR(25/77)
Algorithm
2018. 1. 9. 10:44
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.math.*;
public class Solution {
static long theGreatXor(long x){
long result=0;
long squareNumber = (long) (Math.log(x)/Math.log(2));
long squaredValue = (long) Math.pow(2,squareNumber);
long minusValue = x-squaredValue+1;
result = squaredValue-minusValue;
return result;
}
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);
}
}
}
'Algorithm' 카테고리의 다른 글
[LuckyAlgorithm]Sherlock and Array(27/77) [진행중] (0) | 2018.01.18 |
---|---|
[LuckyAlgorithm]Permuting Two Arrays(26/77) (0) | 2018.01.18 |
[LuckyAlgorithm]Utopian Tree(24/77) (0) | 2018.01.04 |
[LuckyAlgorithm]maximizing-xor(23/77) (0) | 2018.01.03 |
[LuckyAlgorithm]Day 26: Nested Logic(22/77) (0) | 2017.12.16 |