感受
思路
第1位:0 1 0 1 0 1 0 1
第2位:0 0 1 1 0 0 1 1
第3位:0 0 0 0 1 1 1 1
第4位:0 0 0 0 0 0 0 0
第1位:0 1| 0 1 0 1| 0 1
第2位:0 0| 1 1 0 0| 1 1
第3位:0 0| 0 0 1 1| 1 1
第4位:0 0| 0 0 0 0| 0 0
第1位:0 1 0 1 0 1| 0 1|
第2位:0 0 1 1 0 0| 1 1|
第3位:0 0 0 0 1 1| 1 1|
第4位:0 0 0 0 0 0| 0 0|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e5 + 10;
const ll mod = 998244353;
ll l, r;
bool check(ll x, ll y, int k){
x >>= k; y >>= k;
if((x & 1) ^ (y & 1)) return true;
return false;
}
int main(){
//ull a = 1;
//printf("%llu\n", a << 60);
int t;
scanf("%d", &t);
while(t--){
scanf("%lld%lld", &l, &r);
int i;
for(i = 60; i >= 0; i--){
if(check(l, r, i)) break;
}
i++;
ll ans = 1;
printf("%lld\n", (ans << i) - 1);
}
return 0;
}



京公网安备 11010502036488号