CF119A.Epic Game
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
西蒙和安蒂西蒙玩一个游戏。游戏开始时,每位玩家会获得一个固定的正整数,且该数在整局游戏中保持不变。西蒙获得数字 a,安蒂西蒙获得数字 b。此外,他们还拥有一堆共 n 颗石子。两位玩家轮流进行操作,西蒙先手。在每次操作中,当前玩家需从石子堆中取走数量等于“自己所持固定数字”与“当前剩余石子数”之最大公约数(GCD)的石子。当某位玩家无法取走所需数量的石子时(即:剩余石子数严格小于所需取走的石子数),该玩家判负。
你的任务是:给定 a、b 和 n,判断哪位玩家获胜。
输入格式
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
唯一的一行输入包含用空格分隔的三个整数 a、b 和 n(1 ≤ a, b, n ≤ 100)——分别表示西蒙和安蒂西蒙收到的固定数字,以及石堆中初始的石子数量。
输出格式
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
如果西蒙获胜,输出“0”(不带引号),否则输出“1”(不带引号)。
输入输出样例
输入#1
3 5 9
输出#1
0
输入#2
1 1 100
输出#2
1
说明/提示
The greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
- Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
- Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
- Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
- Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
- Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
- Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that.
两个非负整数 a 和 b 的最大公约数(GCD)是指满足以下条件的最大正整数 k:a 能被 k 整除(即余数为 0),且 b 也能被 k 整除。记 gcd(a,b) 表示计算 a 与 b 的最大公约数的运算。特别地,有 gcd(x,0)=gcd(0,x)=x。
在第一个样例中,游戏过程如下:
- Simon 应从堆中取走 gcd(3,9)=3 颗石子。他操作后,堆中剩余 6 颗石子。
- Antisimon 应从堆中取走 gcd(5,6)=1 颗石子。他操作后,堆中剩余 5 颗石子。
- Simon 应从堆中取走 gcd(3,5)=1 颗石子。他操作后,堆中剩余 4 颗石子。
- Antisimon 应从堆中取走 gcd(5,4)=1 颗石子。他操作后,堆中剩余 3 颗石子。
- Simon 应从堆中取走 gcd(3,3)=3 颗石子。他操作后,堆中剩余 0 颗石子。
- Antisimon 应从堆中取走 gcd(5,0)=5 颗石子。但由于 0<5,该操作无法执行,因此 Antisimon 失败。
在第二个样例中,每位玩家在每一轮操作中均从堆中取走 1 颗石子。由于 n 是偶数,Antisimon 将取走最后一颗石子,之后 Simon 无法再进行操作。
输入解题思路,AI测评打分。不知道怎么写?