### MEXor Mixup（源地址自​​⇔CF742B​​）

#### Problem

Alice gave Bob two integers $$a$$ and $$b$$ ( $$a>0$$ and $$b≥0$$ ). Being a curious boy, Bob wrote down an array of non-negative integers with $$MEX$$ value of all elements equal to $$a$$ and $$XOR$$ value of all elements equal to $$b$$ .
What is the shortest possible length of the array Bob wrote?
Recall that the $$MEX$$ (Minimum EXcluded) of an array is the minimum non-negative integer that does not belong to the array and the $$XOR$$ 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 $$t$$ ( $$1≤t≤5*10^4$$ ) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers $$a$$ and $$b$$ ($$1≤a≤3*10^5$$ ; $$0≤b≤3*10^5$$ ) — the $$MEX$$ and $$XOR$$ of the array, respectively.

#### Output

For each test case, output one (positive) integer — the length of the shortest array with $$MEX$$ $$a$$ and $$XOR$$ $$b$$ . We can show that such an array always exists.

5
1 1
2 1
2 0
1 10000
2 10000

3
2
3
2
3

#### Note

In the first test case, one of the shortest arrays with $$MEX$$ $$1$$ and $$XOR$$ $$1$$ is ​​[0,2020,2021]​​.
In the second test case, one of the shortest arrays with $$MEX\ 2$$ and $$XOR\ 1$$ is ​​[0,1]​​.
It can be shown that these arrays are the shortest arrays possible.

⇔位运算、⇔数论（规律题）

#### 题意

1 . 数组内元素必须是 $$\geq 0$$ 的。
2 . $$a$$ 是不包含再这个数组里的最小正整数。
3 . 数组中所有元素的按位异或和恰好等于 $$b$$ 。

#### 思路：

1 . $$b1==b2$$ ，此时，直接输出即可。
2 . $$b1!=b2$$ ，此时，容易证明，一定能找到一个数字 $$k$$ ，使得 $$k\bigoplus b1$$ 答案为 $$b2$$ 。

1 . 若 $$a\bigoplus S_{a-1}==b$$ ，则答案为 $$a+2$$ 。
2 . 若 $$S_{a-1}==b$$ ，则答案为 $$a$$ 。
3 . 其余情况答案均为 $$a+1$$ 。

#### AC代码：

//A WIDA Project#include<bits/stdc++.h>using namespace std;int a,b,a1,b1,T,numa,numb,M[300030];void Prepare(){//计算按位异或和  bitset<100>B1;bitset<100>B2;  B2=0;  for(int i=0;i<300005;i++){    B1=i;    B2=B1^B2;    M[i]=B2.to_ullong();  }}int main(){  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  cin>>T;  for(int t=1;t<=T;t++){    cin>>a>>b;    if(M[a-1]==b) cout<<a<<"\n";    else if(M[a]==b) cout<<a+2<<"\n";    else cout<<a+1<<"\n";  }  return 0;}

2021.09.06成文