Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <ctime>
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10.  
  11. ll solve(ll a, ll b)
  12. {
  13.     if ((__builtin_popcountll(a) & 1) != (__builtin_popcountll(b) & 1))
  14.         return 0;
  15.     ll len = 0;
  16.     if (a & 1)
  17.         len++, a++, b++;
  18.     if ((a & 1) == (b & 1))
  19.         return len + 2 * solve(a / 2, b / 2);
  20.     while ((__builtin_popcountll(a) & 1) == (__builtin_popcountll(b) & 1))
  21.         a++, b++, len++;
  22.     return len;
  23. }
  24.  
  25. int main()
  26. {
  27.     freopen ("treasure.in", "r", stdin);
  28.     freopen ("treasure.out", "w", stdout);
  29.     int n;
  30.     scanf("%d", &n);
  31.     for (int i = 0; i < n; i++)
  32.     {
  33.         ll a, b;
  34.         scanf("%lld%lld", &a, &b);
  35.         printf("%lld\n", solve(a, b));
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement