Min Bits

4.1

9 votes
Bit manipulation, Bit Manipulation, Basics of Bit Manipulation, Basic Programming
Problem

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

Time Limit: 2
Memory Limit: 256
Source Limit:
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).

Editor Image

?