CF2137C.Maximum Even Sum

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Maximum Even Sum

You are given two integers aa and bb. You are to perform the following procedure:

First, you choose an integer kk such that bb is divisible by kk. Then, you simultaneously multiply aa by kk and divide bb by kk.

Find the greatest possible even value of a+ba+b. If it is impossible to make a+ba+b even, output 1-1 instead.

Input

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

The first line of each test case contains two integers aa and bb (1a,bab1018)1 \leq a,b \leq a\cdot b \leq 10^{18}).

Output

For each test case, output the maximum even value of a+ba+b on a new line.

Note

In the first test case, it can be shown it is impossible for a+ba+b to be even.

In the second test case, the optimal kk is 22. The sum is 2+4=62+4=6.

Samples

7
8 1
1 8
7 7
2 6
9 16
1 6
4 6
-1
6
50
8
74
-1
14

在线编程 IDE

建议全屏模式获得最佳体验