CF1844A.Subtraction Game

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two positive integers, aa and bb ( a<ba < b ).

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

Find a positive integer nn 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.

输入格式

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

The only line of each test case contains two integers, aa and bb ( 1a<b1001 \le a < b \le 100 ).

输出格式

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

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

输入输出样例

  • 输入#1

    3
    1 4
    1 5
    9 26

    输出#1

    2
    6
    3

说明/提示

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

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

  • If they remove b=5b = 5 stones, then the second player can respond by removing a=1a = 1 stone. The first player can no longer make a move, so the second player wins.
  • If they remove a=1a = 1 stone, then the second player can respond by removing a=1a = 1 stone. Afterwards, the players can only alternate removing exactly a=1a = 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=3n = 3 , so the second player immediately wins.

首页