// Problem: 兔子的区间密码
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/20960/1052
// Memory Limit: 65536 MB
// Time Limit: 2000 ms
// 2022-02-21 21:35:06
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define mp make_pair
const ll mod = 1e9 + 7;
inline int read () {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f?-x:x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x/10);
putchar(x % 10 + '0');
}
string get (ll x) {
string s = "";
while(x) {
if (x & 1)
s += "1";
else s += "0";
x >>= 1;
}
reverse(s.begin(), s.end());
return s;
}
ll qmi(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans = ans * a;
a = a * a;
b >>= 1;
}
return ans;
}
void solve() {
ll l, r;
scanf("%lld%lld", & l, & r);
string a= get (l), b = get (r);
while (a.size() < b.size())
a = "0" + a;
while (b.size() < a.size())
b = "0" + b;
// cout << a << ' ' << b << endl;
int n = a.size();
ll id = 0;
if (a == b) {
puts("0");
return;
}
for (int i = 0; i < n; i ++) {
if (a[i] == '0' && b[i] == '1') {
id = n - i;
break;
}
}
// cout << id <<endl;
ll ans = qmi(2, id) - 1;;
printf("%lld\n", ans);
// puts("--0-");
}
int main () {
int t;
t =1;
cin >> t;
while (t --) solve();
return 0;
}
从高位往低位贪。 一样的不要了。 直到遇到第一个不一样的并且l[i] = '0', r[i] = 1;这样就可以保证后面的数都是>=l&&<=r的