Rayan Programming Contest 2024 - Selection (Codeforces Round 989, Div. 1 + Div. 2)
A
King Keykhosrow's Mystery
Codeforces
800
原题
←B →
翻译中…

There is a tale about the wise King Keykhosrow who owned a grand treasury filled with treasures from across the Persian Empire. However, to prevent theft and ensure the safety of his wealth, King Keykhosrow's vault was sealed with a magical lock that could only be opened by solving a riddle.

翻译中…

image

翻译中…

The riddle involves two sacred numbers $a$ and $b$. To unlock the vault, the challenger must determine the smallest key number $m$ that satisfies two conditions:

翻译中…
  • $m$ must be greater than or equal to at least one of $a$ and $b$.
  • The remainder when $m$ is divided by $a$ must be equal to the remainder when $m$ is divided by $b$.
翻译中…

Only by finding the smallest correct value of $m$ can one unlock the vault and access the legendary treasures!

翻译中…

Input

翻译中…

The first line of the input contains an integer $t$ ($1 \leq t \leq 100$), the number of test cases.

翻译中…

Each test case consists of a single line containing two integers $a$ and $b$ ($1 \leq a, b \leq 1000$).

翻译中…

Output

翻译中…

For each test case, print the smallest integer $m$ that satisfies the conditions above.

翻译中…

Note

翻译中…

In the first test case, you can see that:

翻译中…
  • $4 \bmod 4 = 0$ but $4 \bmod 6 = 4$
  • $5 \bmod 4 = 1$ but $5 \bmod 6 = 5$
  • $6 \bmod 4 = 2$ but $6 \bmod 6 = 0$
  • $7 \bmod 4 = 3$ but $7 \bmod 6 = 1$
  • $8 \bmod 4 = 0$ but $8 \bmod 6 = 2$
  • $9 \bmod 4 = 1$ but $9 \bmod 6 = 3$
  • $10 \bmod 4 = 2$ but $10 \bmod 6 = 4$
  • $11 \bmod 4 = 3$ but $11 \bmod 6 = 5$
翻译中…

so no integer less than $12$ satisfies the desired properties.

翻译中…

样例

Input #1
2
4 6
472 896
Output #1
12
52864
InputCopy OutputCopy
题目信息
题号
2034A
时间限制
1 s
内存限制
256 MB
标签
暴力
中国剩余定理
数学
数论

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