CF BUDDY
← Problems·

1603B · Moderate Modular Mode

1600 · constructive algorithms, math, number theory

Problem: YouKn0wWho has two even integers xx and yy. Help him to find an integer nn such that 1n210181 \le n \le 2 \cdot 10^{18} and nmodx=ymodnn \bmod x = y \bmod n. Here, amodba \bmod b denotes the remainder of aa after division by bb. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.

Input Format: The first line contains a single integer tt (1t1051 \le t \le 10^5)  — the number of test cases.

The first and only line of each test case contains two integers xx and yy (2x,y1092 \le x, y \le 10^9, both are even).

Output Format: For each test case, print a single integer nn (1n210181 \le n \le 2 \cdot 10^{18}) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.

Note: In the first test case, 4mod4=8mod4=04 \bmod 4 = 8 \bmod 4 = 0.

In the second test case, 10mod4=2mod10=210 \bmod 4 = 2 \bmod 10 = 2.

In the third test case, 420mod420=420mod420=0420 \bmod 420 = 420 \bmod 420 = 0.

Sample Cases

Case 1

Input

4
4 8
4 2
420 420
69420 42068

Output

4
10
420
9969128

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback