Codeforces Round 884 (Div. 1 + Div. 2)
A
Subtraction Game
Codeforces
800
原题
←B →
翻译中…

You are given two positive integers, $a$ and $b$ ($a \lt b$).

翻译中…

For some positive integer $n$, two players will play a game starting with a pile of $n$ stones. They take turns removing exactly $a$ or exactly $b$ stones from the pile. The player who is unable to make a move loses.

翻译中…

Find a positive integer $n$ such that the second player to move in this game has a winning strategy. This means that no matter what moves the first player makes, the second player can carefully choose their moves (possibly depending on the first player's moves) to ensure they win.

翻译中…

Input

翻译中…

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

翻译中…

The only line of each test case contains two integers, $a$ and $b$ ($1 \le a \lt b \le 100$).

翻译中…

Output

翻译中…

For each test case, output any positive integer $n$ ($1 \le n \le 10^6$) such that the second player to move wins.

翻译中…

It can be proven that such an $n$ always exists under the constraints of the problem.

翻译中…

Note

翻译中…

In the first test case, when $n = 2$, the first player must remove $a = 1$ stone. Then, the second player can respond by removing $a = 1$ stone. The first player can no longer make a move, so the second player wins.

翻译中…

In the second test case, when $n = 6$, the first player has two options:

翻译中…
  • If they remove $b = 5$ stones, then the second player can respond by removing $a = 1$ stone. The first player can no longer make a move, so the second player wins.
  • If they remove $a = 1$ stone, then the second player can respond by removing $a = 1$ stone. Afterwards, the players can only alternate removing exactly $a = 1$ stone. The second player will take the last stone and win.
翻译中…

Since the second player has a winning strategy no matter what the first player does, this is an acceptable output.

翻译中…

In the third test case, the first player cannot make any moves when $n = 3$, so the second player immediately wins.

翻译中…

样例

Input #1
3
1 4
1 5
9 26
Output #1
2
6
3
InputCopy OutputCopy
题目信息
题号
1844A
时间限制
1 s
内存限制
256 MB
标签
构造
博弈论

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