Codeforces Round 843 (Div. 2)
C
Interesting Sequence
Codeforces
1600
原题
← BD →
翻译中…

Petya and his friend, robot Petya++, like to solve exciting math problems.

翻译中…

One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation. Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.

翻译中…

Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.

翻译中…

Can you solve this difficult problem?

翻译中…

image

翻译中…

Input

翻译中…

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

翻译中…

The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).

翻译中…

Output

翻译中…

For every test case, output the smallest possible value of $m$ such that equality holds.

翻译中…

If the equality does not hold for any $m$, print $-1$ instead.

翻译中…

We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.

翻译中…

Note

翻译中…

In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.

翻译中…

In the second example, $10 = 10$, so the answer is $10$.

翻译中…

In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.

翻译中…

样例

Input #1
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output #1
12
10
-1
24
1152921504606846976
InputCopy OutputCopy
题目信息
题号
1775C
时间限制
1 s
内存限制
256 MB
标签
位运算
数学

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