SWUST OJ Euclid's Game(0099)

Euclid's Game(0099)

Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 1855 Accepted: 589
 
Description
Starts with two unequal positive numbers (M,N and M>N) on the board. Two players move in turn. On each move, a player has to write on the board a positive number equal to the difference of two numbers already on the board; this number must be new, i.e., different from all the numbers already on the board. The player who cannot move loses the game. Should you choose to move first or second in this game? 
 
According to the above rules, there are two players play tihs game. Assumptions A write a number on the board at first, then B write it. 

Your task is write a program to judge the winner is A or B.
 
(由两个不等正数开始,这两个数写在板子上,M>N,每人只能在板上写出板子上已有数的差值的绝度值,这个值必须是和之前不同的。谁不能写出谁即输掉这场游戏,所以你是该先手还是后手,才能赢得这场比赛?)
 
(根据这个规则,假定A首先写,然后B写)
 
(你的任务是写个程序判断谁是赢家)
 
Input
Two unequal positive numbers M and N , M>N (M<1000000)
 
Output
A or B
 
Sample Input
3 1
 
Sample Output
A
 
Hint
Source
algorithm text book
 
#include<stdio.h>
int gcd(int a,int b)
{
    int c;
    while(c)
    {
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if((a/gcd(a,b))%2==0)
        printf("B\n");
    else
        printf("A\n");
return 0;
}

 

注:每次写的数,只能是最开始两个数的最大公约数的k(k最大为M/gcd(M,N))倍,所以判断M/gcd(M,N)奇偶性即可。

posted on 2015-05-03 22:53  _飛  阅读(502)  评论(0编辑  收藏  举报

导航