Codeforces Round 1011 (Div. 2)
C
Serval and The Formula
Codeforces
1600
原题
← BD →
翻译中…

You are given two positive integers $x$ and $y$ ($1\le x, y\le 10^9$).

翻译中…

Find a non-negative integer $k\le 10^{18}$, such that $(x+k) + (y+k) = (x+k)\oplus (y+k)$ holds$^{\text{∗}}$, or determine that such an integer does not exist.

翻译中…

$^{\text{∗}}$$\oplus$ denotes the bitwise XOR operation.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The only line of each test case contains two integers $x$ and $y$ ($1\le x, y\le 10^9$) — the given integers.

翻译中…

Output

翻译中…

For each test case, output a single integer $k$ ($0\le k\le 10^{18}$) — the integer you found. Print $-1$ if it is impossible to find such an integer.

翻译中…

If there are multiple answers, you may print any of them.

翻译中…

Note

翻译中…

In the first test case, since $(2 + 0) + (5 + 0) = (2 + 0) \oplus (5 + 0) = 7$, $k=0$ is a possible answer. Note that $k=4$ is also a possible answer because $(2 + 4) + (5 + 4) = (2 + 4) \oplus (5 + 4) = 15$.

翻译中…

In the second test case, $(x+k)\oplus (y+k) = (6+k)\oplus (6+k) = 0$. However, $(x+k)+(y+k) \gt 0$ holds for every $k \ge 0$, implying that such an integer $k$ does not exist.

翻译中…

样例

Input #1
5
2 5
6 6
19 10
1024 4096
1198372 599188
Output #1
0
-1
1
1024
28
InputCopy OutputCopy
题目信息
题号
2085C
时间限制
2 s
内存限制
256 MB
标签
位运算
构造
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。