C. Bits
题意:在一个区间[l,r]内找出二进制下"1"最多的数,如果有多解,输出最小的数。
思路:贪心。从l开始,从低位到高位,逐位或1,如果或结果不比r大,就或上去。
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int main(){
int t;
cin>>t;
while(t--){
ll l,r;
cin>>l>>r;
ll cur=l;
ll tmp=1;
while(tmp<r){
if((cur|tmp)<=r)cur|=tmp;
tmp<<=1;
}
cout<<cur<<endl;
}
return 0;
}