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.
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.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
- #include
- 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;
- }