Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
33770 | LYLAKIOIAKIOI | 【S】T1 | C++ | 运行超时 | 60 | 1000 MS | 256 KB | 622 | 2024-10-22 15:05:55 |
//100 kachang endl->'\n' #include<bits/stdc++.h> #define ll long long using namespace std; ll solve(ll a,ll b){ if(a==b) return 1; int l=0,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)<<'\n'; } return 0; }