https://ac.nowcoder.com/acm/problem/20860
题解:区间两端异或值的二进制位数一定是最大值的位数,那么我们将二进制位数上的值全部变为1.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <utility>
#include <queue>
#include <map>
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=1e5+5;
void io() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); }
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
inline void write(int x)
{ //不能输出0
char F[200];
int tmp=x>0?x:-x ;
if(x<0)putchar('-') ;
int cnt=0 ;
while(tmp>0)
{
F[cnt++]=tmp%10+'0';
tmp/=10;
}
while(cnt>0)putchar(F[--cnt]) ;
}
signed main() {
int test=1; test=read();
while(test--) {
int l,r;
l=read();r=read();
ll t=l^r,ans=0;
while(t) {
ans=ans*2+1;
t>>=1;
}
printf("%lld\n",ans);
}
}