提交时间:2024-10-22 15:02:31

运行 ID: 33769

//100 #include<bits/stdc++.h> #define ll long long using namespace std; ll solve(ll a,ll b){ if(a==b) return 1; int l=1,r=62; while(l<r){ int mid=(l+r+1)/2; ll tmp=(1ll<<mid)-1; if(a-(a&tmp)==b-(b&tmp)) r=mid-1; else l=mid; }ll tmp=(1ll<<l)-1; //cout<<tmp<<endl; ll a1=a&tmp,b1=b&tmp; ll c=1;while(c<=b1) c<<=1; ll p=tmp+1-(a&tmp); //cout<<p<<endl; ll q=min(c,a&tmp); return p+p+q; } int main(){ int t;cin>>t; while(t--){ ll l,r;cin>>l>>r;cout<<solve(l,r)<<endl; } return 0; }