Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <map>
  5. #include <set>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. vector<long long> f(61);
  11.  
  12. long long argh(long long a)
  13. {
  14. long long p=0,ans=0,k=1,null=0;
  15. while(1<<p < a)
  16. {
  17. p++;
  18. }
  19. for(;p>=0;p--)
  20. {
  21. if((a&(1<<p))==1)
  22. {
  23. ans+=max(f[p]+k,null);
  24. k=-k;
  25. }
  26. }
  27. return ans;
  28. }
  29.  
  30. int main()
  31. {
  32. long long n,a,b;
  33. cin>>n;
  34.  
  35. f[0]=0;
  36. f[1]=1;
  37. f[2]=2;
  38. for(int i=3;i<61;i++)
  39. {
  40. f[i]=f[i-1]*2;
  41. }
  42. for(int i=0;i<n;i++)
  43. {
  44. cin>>a>>b;
  45. int ans1=argh(a-1),ans2=argh(b);
  46. cout<<ans1<<endl<<ans2<<endl<<ans2-ans1<<endl;
  47.  
  48. }
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement