A. Bits

来源:互联网 发布:淘宝上的avada主题 编辑:程序博客网 时间:2024/06/07 03:44

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's denote as  the number of bits set ('1' bits) in the binary representation of the non-negative integerx.

You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and  is maximum possible. If there are multiple such numbers find the smallest of them.

Input

The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).

Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).

Output

For each query print the answer in a separate line.

Examples
input
31 22 41 10
output
137
Note

The binary representations of numbers from 1 to 10 are listed below:

110 = 12

210 = 102

310 = 112

410 = 1002

510 = 1012

610 = 1102

710 = 1112

810 = 10002

910 = 10012

1010 = 10102


解题说明:此题只需要把数字转换为二进制,然后统计1的次数,最后找到一个区间内1最多的数。


#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;int main() {    int n;    long long l,r;    cin>>n;    for(int i=0;i<n;i++) {cin>>l>>r;while((l|(l+1))<=r) {l|=l+1;}cout<<l<<endl;}    return 0;}


0 0