Euclid's Game

来源:互联网 发布:矩阵求行列式的公式 编辑:程序博客网 时间:2024/05/11 09:09
Description

Starts with two unequal positive numbers (M,N andM>N) on the board. Two players move in turn. On eachmove, a player has to write on the board a positive number equal tothe difference of two numbers already on the board; this numbermust be new, i.e., different from all the numbers already on theboard. The player who cannot move loses the game. Should you chooseto 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 writeit.

Your task is write a program to judge the winner is A or B.

Input

Two unequal positive numbers M and N , M>N(M<1000000)

Output

A or B

Sample Input

3 1

Sample Output

A

 

 

 

#include<iostream>
using namespace std;
int f(int m, int n)
  int t;
 while(n!=0)
 {
   t=m%n;
   m=n;
   n=t;
 }
 return m;
}
int main()
{
 int m,n;
 cin>>m>>n;
    if ((m/f(m,n) )%2==0)
  cout<<"B"<<endl;
  elsecout<<"A"<<endl;

}

0 0
原创粉丝点击