Min Bits
Bit manipulation
Bit manipulation
Basics of bit manipulation
Basic programming
49.0% success
5,008 attempts
2s time
256MB memory
1024KB max code

Your college professor has given you a task to pass the semester. The task is as follows:

You are given 2 integers L and R which denotes a range. Find a number in between(L and R inclusive) which has the minimum number of set bits count. If there are multiple such numbers, print the minimum number.
Note: 14 can be written as 1110 in binary and its set bit count is 3.

Input

First line containing 1 integer T

Next T line containing 2 integers L and R.

Output

A single integer, denoting the number with minimum set bit count.

Constraints
1 <= T <= 100000
1 <= L <= R <= 10^18

Examples
Input
1
10 1000
Output
16
Explanation

16 has a total of 1 set bits. It is also the minimum number in the range 10 to 100 that has 1 set bit(s).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading Editor...