Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <map>
- #include <set>
- #include <cmath>
- using namespace std;
- vector<long long> f(61);
- long long argh(long long a)
- {
- long long p=0,ans=0,k=1,null=0;
- while(1<<p < a)
- {
- p++;
- }
- for(;p>=0;p--)
- {
- if((a&(1<<p))==1)
- {
- ans+=max(f[p]+k,null);
- k=-k;
- }
- }
- return ans;
- }
- int main()
- {
- long long n,a,b;
- cin>>n;
- f[0]=0;
- f[1]=1;
- f[2]=2;
- for(int i=3;i<61;i++)
- {
- f[i]=f[i-1]*2;
- }
- for(int i=0;i<n;i++)
- {
- cin>>a>>b;
- int ans1=argh(a-1),ans2=argh(b);
- cout<<ans1<<endl<<ans2<<endl<<ans2-ans1<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement