AtCoder Regular Contest 208 (Div. 2)
C
Mod of XOR
AtCoder
⌀ 1849
原题
← BD →
翻译中…

Problem Statement

翻译中…

You are given positive integers $C$ and $X$ that are less than $2^{30}$.

翻译中…

Determine whether there exists a positive integer $n$ that satisfies all of the following conditions, and if it exists, find one such $n$.

翻译中…
  • $1\le n < 2^{60}$
  • $(n \oplus C) \bmod n=X$
翻译中…

Here, $n \oplus C$ denotes the bitwise $\mathrm{XOR}$ of $n$ and $C$.

翻译中…

You are given $T$ test cases, solve each of them.

翻译中…

What is bitwise $\mathrm{XOR}$? The bitwise $\mathrm{XOR}$ of non-negative integers $X$ and $Y$, $X \oplus Y$, is defined as follows: When $X \oplus Y$ is written in binary, the digit in the $2^k$ place ($k \geq 0$) is $1$ if exactly one of the digits in the $2^k$ place of $X$ and $Y$ written in binary is $1$, and $0$ otherwise. For example, $3 \oplus 5 = 6$ (in binary: $011 \oplus 101 = 110$).

翻译中…

Constraints

翻译中…
  • $1\le T\le 2\times 10^5$
  • $1\le C,X < 2^{30}$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

C X

翻译中…

Output

翻译中…

Output the answers for each test case in order, separated by newlines.

翻译中…

For each test case, if there does not exist an $n$ that satisfies all conditions, print -1.

翻译中…

Otherwise, print $n$ that satisfies all conditions.

翻译中…

If there are multiple $n$ that satisfy all conditions, any of them will be accepted.

翻译中…

样例

Input #1
3
10 6
2 3
777 153
Output #1
7
-1
208
Consider the first test case. $n=7$ satisfies all conditions because $(n\oplus C) \bmod n = (7 \oplus 10) \bmod 7 = 13\bmod 7 = 6=X$. Therefore, printing $7$ on the first line will be accepted. Other than this, printing $n=12,18,19$ etc. will also be accepted.
题目信息
题号
arc208_c
时间限制
2 s
内存限制
1024 MB

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