Description
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.
Input
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.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Sample Input
Sample Output
#include <stdio.h>
int gcd(int a,int b){//求最大公约数
int t=1,max,min;
if(a>=b) max=a,min=b;
else max=b,min=a;
while(t){
t=max%min;
max=min;
min=t;
}
return max;
}
int main()
{
int a,b,n,s,f;
while(~scanf("%d%d%d",&a,&b,&n)){
s=1,f=1;//s=1表示Simon赢,0为输,f用来记录当前是谁进行游戏,f=1是Simon,2为Antisimon
while(1){
//当前是Simon操作
if(f==1){
if(n>0&&n>=gcd(a,n)) n-=gcd(a,n),f=2;//石子数量够
else{
s=1;//石子不够,Simon输
break;
}
}else{
//当前是Antisimon操作
if(n>0&&n>=gcd(b,n)) n-=gcd(b,n),f=1;
else{
s=0;//石子不够,Antisimon输,也就是Simon赢
break;
}
}
}
printf("%d\n",s);
}
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。