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);
			}
		}
	}










}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

算法编程张老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值