


a ⊕ b = X, where ⊕ denotes bitwise xor operation.
Both numbers ‘a’ and ‘b’ belong to the array ‘A’.
The first line contains 'T', denoting the number of tests.
For each Test :
The only line contains two space-separated integers 'L' and 'R', denoting the endpoints of the array.
For each test, print an integer, denoting the maximum possible xor of two elements from the array.
You are not required to print the expected output. It has already been taken care of. Just implement the function.
1 <= 'T' <= 10^3
1 <= 'L' <= 'R' <= 10^9
Time Limit: 1 sec
Algorithm:
In our pair (a, b), both numbers should be in the range [L, R], then the position of MSB (from right to left in binary) in a⊕b can never be greater than in L⊕R.
Let’s understand by an example.
Let L = 16 and R = 20.
L ⊕ R = (10000) ⊕ (10100) = (00100). Here, MSB is in 3rd position from the right side, which ensures that MSB can’t exceed the 3rd position for any pair (a, b) in the range [L, R]. Currently, our answer is 1xxxxx, where we know the position of bit ‘1’.
Now, the question arises, what to do with the remaining positions/bits?
To answer this question, our another observation is that, the position where we got MSB in L⊕R, one among L and R has bit ‘1’ at that place and another has bit ‘0’. So in the given range, at least once, the number is changed from ‘1111…..’ to ‘1000…..’ i.e., (2^p - 1) to (2^p). Hence it is always possible to choose combinations such that in 1xxxxx, each bit becomes ‘1’.
Algorithm: