| Codeforces Round 1047 (Div. 3) |
|---|
| Finished |
You are given two integers $$$a$$$ and $$$b$$$. You are to perform the following procedure:
First, you choose an integer $$$k$$$ such that $$$b$$$ is divisible by $$$k$$$. Then, you simultaneously multiply $$$a$$$ by $$$k$$$ and divide $$$b$$$ by $$$k$$$.
Find the greatest possible even value of $$$a+b$$$. If it is impossible to make $$$a+b$$$ even, output $$$-1$$$ instead.
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 first line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \leq a,b \leq a\cdot b \leq 10^{18})$$$.
For each test case, output the maximum even value of $$$a+b$$$ on a new line.
78 11 87 72 69 161 64 6
-1 6 50 8 74 -1 14
In the first test case, it can be shown it is impossible for $$$a+b$$$ to be even.
In the second test case, the optimal $$$k$$$ is $$$2$$$. The sum is $$$2+4=6$$$.
| Name |
|---|


