Min Bits
Practice
4.1 (9 votes)
Bit manipulation
Bit manipulation
Basics of bit manipulation
Basic programming
Problem
51% Success 3535 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB 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

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...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
3 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationEasyLogic-BasedString Manipulation
Points:30
17 votes
Tags:
ApprovedBasic ProgrammingBit manipulationMathMedium
Points:30
11 votes
Tags:
ArraysBasic ProgrammingBit ManipulationBit manipulationJavaMediumPython