Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <vector>
- #include <algorithm>
- #include <ctime>
- using namespace std;
- typedef long long ll;
- ll solve(ll a, ll b)
- {
- if ((__builtin_popcountll(a) & 1) != (__builtin_popcountll(b) & 1))
- return 0;
- ll len = 0;
- if (a & 1)
- len++, a++, b++;
- if ((a & 1) == (b & 1))
- return len + 2 * solve(a / 2, b / 2);
- while ((__builtin_popcountll(a) & 1) == (__builtin_popcountll(b) & 1))
- a++, b++, len++;
- return len;
- }
- int main()
- {
- freopen ("treasure.in", "r", stdin);
- freopen ("treasure.out", "w", stdout);
- int n;
- scanf("%d", &n);
- for (int i = 0; i < n; i++)
- {
- ll a, b;
- scanf("%lld%lld", &a, &b);
- printf("%lld\n", solve(a, b));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement