1567B - MEXor Mixup - CodeForces Solution


bitmasks greedy *1000

Please click on ads to support us..

Python Code:

T = int(input())
for _ in range(T):
    a,b = map(int,input().split())
    j = [0,a-1,1,a]
    X = j[a % 4]
    if b == X:
        print(a)
    elif X ^ a == b:
        print(a+2)
    else:
        print(a+1)

C++ Code:

// 1677670931266
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int unsigned long long int
#define mod 1000000007
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define trace(x) cerr << #x << " : " << x << endl;
// #define first cout << "first" << endl;
// #define second cout << "second" << endl;
#define pb push_back
const int e = 1e6;
int fast_pow(int a, int p)
{
  int ret = 1.;
  for (; p; p /= 2, a = ((a % e) * (a % e)) % e)
    if (p & 1)
      ret = (ret % e * a % e) % e;
  return ret % e;
}
int arr[e];
void solve2()
{
  int xr = 0;
  for (int i = 0; i < e; i++)
  {
    xr ^= i;
    arr[i] = xr;
  }
}

void solve()
{
  int n, m;
  cin >> n >> m;
  if (n == 0)
  {
    cout << 2 << endl;
  }
  else
  {

    int ans = arr[n - 1];
    int ans2 = ans ^ m;

    if (ans == m)
    {
      cout << n << endl;
    }
    else if (ans2 == n)
    {
      cout << n + 2 << endl;
    }
    else
    {
      cout << n + 1 << endl;
    }
  }
}

int32_t main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;

  solve2();
  while (t--)
  {
    solve();
  }

  return 0;
}


Comments

Submit
0 Comments
More Questions

1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima