
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains a single integer ‘N’ denoting the given number.
For each test case, return the number after doing its complement.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10 ^ 6
Time Limit: 1 sec
The idea here is to divide the number by ‘2’ as for converting a number from decimal to binary we need to divide it by ‘2’ while dividing we can think of taking complement as if we get remainder ‘1’ we can store it as ‘0’ and if we get ‘0’ we can store it as ‘1’.
The idea here is to use the concept that the xor of a number with its xor mask gives us the complement of the number. Xor mask of a number is greater than or equal to the number which has exactly the same number of bits as the given number and all bits of the xor mask is 1.
For example, 1 1 0 its xor mask is equal to 1 1 1 so we can think of as complement of a number is the value obtained by swapping ‘1’ with ‘0’ and vice versa so we can say when we take xor with its xor mask so according to xor when we encounter the same element it returns ‘0’ and if it is different it returns ‘1’.
So suppose given binary number is 1 1 0 its xor mask will be 1 1 1 on taking xor we get 0 0 1 and it is equal to complement.