Codeforces Round #742 (Div. 2)

简介: Codeforces Round #742 (Div. 2)

B. MEXor Mixup

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output


Alice gave Bob two integers aa and bb (a>0a>0 and b≥0b≥0). Being a curious boy, Bob wrote down an array of non-negative integers with MEXMEX value of all elements equal to aa and XORXOR value of all elements equal to bb.


What is the shortest possible length of the array Bob wrote?


Recall that the MEXMEX (Minimum EXcluded) of an array is the minimum non-negative integer that does not belong to the array and the XORXOR of an array is the bitwise XOR of all the elements of the array.


Input


The input consists of multiple test cases. The first line contains an integer tt (1≤t≤5⋅1041≤t≤5⋅104) — the number of test cases. The description of the test cases follows.


The only line of each test case contains two integers aa and bb (1≤a≤3⋅1051≤a≤3⋅105; 0≤b≤3⋅1050≤b≤3⋅105) — the MEXMEX and XORXOR of the array, respectively.


Output


For each test case, output one (positive) integer — the length of the shortest array with MEXMEX aa and XORXOR bb. We can show that such an array always exists.


Example


input


Copy

5

1 1

2 1

2 0

1 10000

2 10000


output


Copy

3

2

3

2

3


Note

In the first test case, one of the shortest arrays with MEXMEX 11 and XORXOR 11 is [0,2020,2021][0,2020,2021].


In the second test case, one of the shortest arrays with MEXMEX 22 and XORXOR 11 is [0,1][0,1].

It can be shown that these arrays are the shortest arrays possible.


直接贴代码,分类讨论就行了、


#include <bits/stdc++.h>
using namespace std;
#define ll long long
 signed  main() {
  ll t;
  cin >> t;
  int g[300001];
  for (int i = 1; i <= 300000; i++) {
    g[i] = g[i - 1] ^ i;
  }
  while (t--) {
    ll n, m;
    cin >> n;
    cin >> m;
    ll ans = n;
    if (g[n - 1] == m) {
      printf("%lld\n", ans);
      continue;
    } else {
      if (m == 0 && g[n - 1] != n) {
        printf("%lld\n", ans + 1);
        continue;
      }
      if ((g[n - 1]^n) == m) {
        printf("%lld\n", ans + 2);
      }
      else {
        printf("%lld\n", ans + 1);
      }
    }
  }
}
相关文章
|
2月前
|
机器学习/深度学习 人工智能 测试技术
Codeforces Round 960 (Div. 2)
Codeforces Round 960 (Div. 2)
|
6月前
Codeforces Round #729 (Div. 2)
【6月更文挑战第4天】在这两个编程问题中,B. Plus and Multiply 要求判断通过加法和乘法操作数组是否能形成目标数 `n`。思路是形如 `x^a + yb = n` 的表达式,如果满足则能构造。C. Strange Function 关注的是找到最小正整数 `x` 使得 `x` 不是 `i` 的因子,计算这些值的和模 `10^9+7`。对于每个 `i`,偶数时 `f(i)` 是 3,奇数时是 2,利用因子与最大公约数计算周期性求和。
36 1
|
人工智能 算法 BI
Codeforces Round 891 (Div. 3)
Codeforces Round 891 (Div. 3)
126 0
Codeforces Round 891 (Div. 3)
Codeforces Round #178 (Div. 2)
在n条电线上有不同数量的鸟, Shaass开了m枪,每一枪打的是第xi条电线上的第yi只鸟,然后被打中的这只鸟左边的飞到第i-1条电线上,右边的飞到i+1条电线上,没有落脚点的鸟会飞走。
53 0
Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕。
50 0
|
人工智能 BI
Codeforces Round 827 (Div. 4)
Codeforces Round 827 (Div. 4)A~G题解
106 0
Codeforces Round #675 (Div. 2) A~D
Codeforces Round #675 (Div. 2) A~D
158 0
Equidistant Vertices-树型dp-Codeforces Round #734 (Div. 3)
Description A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words,
142 0