CF1844A.Subtraction Game

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two positive integers, aa and bb (a<ba \lt 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.

给你两个正整数 aa 和 bb(满足 a<ba \lt b)。

对某个正整数 nn,两名玩家将进行一场游戏,初始时有一堆共 nn 颗石子。双方轮流行动,每次恰好从石子堆中取走 aa 颗或 bb 颗石子。无法进行操作的玩家判负。

请找出一个正整数 nn,使得在此游戏中后手玩家具有必胜策略。也就是说,无论先手玩家如何行动,后手玩家均可根据先手玩家的每一步谨慎地选择自己的行动(策略可能依赖于先手玩家的具体走法),从而确保自己获胜。

输入格式

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

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是测试用例的描述。

每个测试用例仅有一行,包含两个整数 aa 和 bb(1≤a<b≤1001 \le a \lt b \le 100)。

输出格式

For each test case, output any positive integer nn (1≤n≤1061 \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.

对于每个测试用例,输出任意一个正整数 nn(1≤n≤1061 \le n \le 10^6),使得后手玩家获胜。

可以证明:在本题的约束条件下,这样的 nn 总是存在的。

输入输出样例

  • 输入#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.

在第一个测试用例中,当 n=2n = 2 时,先手玩家必须移除 a=1a = 1 颗石子。随后,后手玩家可以回应移除 a=1a = 1 颗石子。此时先手玩家无法再进行任何操作,因此后手玩家获胜。

在第二个测试用例中,当 n=6n = 6 时,先手玩家有两种选择:

  • 若其移除 b=5b = 5 颗石子,则后手玩家可回应移除 a=1a = 1 颗石子。此时先手玩家无法再进行任何操作,因此后手玩家获胜。
  • 若其移除 a=1a = 1 颗石子,则后手玩家可回应移除 a=1a = 1 颗石子。此后,双方只能轮流恰好移除 a=1a = 1 颗石子。后手玩家将取走最后一颗石子并获胜。

由于无论先手玩家如何操作,后手玩家均存在必胜策略,因此该输出是可接受的。

在第三个测试用例中,当 n=3n = 3 时,先手玩家无法进行任何操作,因此后手玩家立即获胜。

输入解题思路,AI测评打分。不知道怎么写?

首页