Advertisement
sherry_ahmos

Untitled

Sep 16th, 2022
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <string>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <algorithm>
  10. #include <cmath>
  11. #include <unordered_map>
  12. #include <unordered_set>
  13. #include <bits/stdc++.h>
  14.  
  15. using namespace std;
  16. #define ll long long
  17. #define nl endl
  18. #define cy cout << "YES\n"
  19. #define cn cout << "NO\n"
  20. #define sz s.size()
  21. #define allv v.begin(), v.end()
  22.  
  23. void sherry()
  24. {
  25.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  26. #ifndef ONLINE_JUDGE
  27.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  28. #endif
  29. }
  30. int arr[500000]{};
  31. void solve()
  32. {
  33.     ll a, b;
  34.     cin >> a >> b;
  35.     ll c = arr[a - 1];
  36.     if (c == b)
  37.         cout << a << nl;
  38.     else
  39.     {
  40.         if ((b ^ c) != a)
  41.             cout << a + 1 << nl;
  42.         else
  43.             cout << a + 2 << nl;
  44.     }
  45. }
  46. int main()
  47. {
  48.     sherry();
  49.     for (int i = 1; i <= 500000; ++i)
  50.         arr[i] = arr[i - 1] ^ i;
  51.     int t;
  52.     cin >> t;
  53.     while (t--)
  54.     {
  55.         solve();
  56.     }
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement