Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
33773 | LYLAKIOIAKIOI | 【S】T1 | C++ | 通过 | 100 | 62 MS | 272 KB | 715 | 2024-10-22 15:09:19 |
//100 kachang '\n' -> ios::sync_with_stdio(0) #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(){ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int t;cin>>t; while(t--){ ll l,r;cin>>l>>r;cout<<solve(l,r)<<'\n'; }cout.flush(); return 0; }