Problem Description
B君和G君聊天的时候想到了如下的问题。
给定自然数l和r ,选取2个整数x,y满足l <= x <= y <= r ,使得x|y最大。
其中|表示按位或,即C、 C++、 Java中的|运算。
Input
包含至多10001组测试数据。
第一行有一个正整数,表示数据的组数。
接下来每一行表示一组数据,包含两个整数l,r。
保证 0 <= l <= r <= 1018。
Output
对于每组数据输出一行,表示最大的位或。
Sample Input
5 1 10 0 1 1023 1024 233 322 1000000000000000000 1000000000000000000
Sample Output
15 1 2047 511 1000000000000000000
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include<cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string.h>
#include<bitset>
typedef long long ll;
using namespace std;
const int inf=0x3f3f3f3f;
//int inf = 2e7+100;
vector<int > v[11111],l[11111];
vector<int> ans;
map<string ,int > mp,vism;
map<int ,string>mp2;
map<string,map<string ,int > >in;
int n,m,s,num;
int G[2222][2222];
int vis[1111],d[22222],p[22222],o[11111],f[11111];
char c[22222];
int dd[11111111];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
long long int a,b,c;
scanf("%lld%lld",&a,&b);
if(a==b)
{
printf("%lld\n",a);
continue;
}
long long int sum=0;
long long int t=0;
//cout<<b<<endl;
for(int i=0;a+t<b;i++)
{
t+=((long long)1<<i);
long long int t1;
//cout<<1<<endl;
t1=((a|t)|b);
// cout<<2<<endl;
b=max(b,t1);
}
//cout<<2<<endl;
printf("%lld\n",b);
}
return 0;
}