贪心 · 例12-兔子的区间密码(位运算\异或)

贪心 · 例12-兔子的区间密码
2^60 > 10^18

#include <bits/stdc++.h>
using namespace std;

signed main(){
    int t; cin >> t;
    while(t--){
        long long l, r; cin >> l >> r;
        if(l == r) {cout << 0 << endl; continue;}
        for(int i = 60; i >= 0; --i){
            if(((r >> i) & 1) && (((l >> i) & 1) == 0)){
                cout << (1ll << (i + 1)) - 1 << endl;
                break;
            }
        }
    }
    
    return 0;
}
posted @ 2025-03-27 09:53  awei040519  阅读(15)  评论(0)    收藏  举报