fork download
  1. import java.util.*;
  2.  
  3. class Main{
  4. public static void main (String[] args){
  5. Scanner in = new Scanner(System.in);
  6. long q, x, res, two;
  7. q = in.nextInt();
  8. for(long i = 0; i < q; ++ i){
  9. x = in.nextLong();
  10. res = 0;
  11. two = 1; // two = 2^0
  12. while(x > 0){
  13. if(x % 2 == 0) // check if the last bit is equal to zero
  14. res += two;
  15. x >>= 1; // moving to the next bit
  16. two <<= 1; // same as two *= 2
  17. }
  18. System.out.println(res);
  19. }
  20. }
  21. }
Success #stdin #stdout 0.1s 35324KB
stdin
1
4294967295
stdout
0