Description
Tom and Tom are playing the Euclidean game. They start from two natural numbers. The first player, James, is able to subtract the largest positive integer multiple of the two numbers as much as possible, as long as the difference is non-negative. Then, the second player was lucky enough to perform the same operation on the two numbers, followed by James. In this way, the game is played in turn until a player returns a large number minus a multiple of a decimal number and returns 0. At this time, the game ends and the player is the winner.
Input Format
The input contains multiple groups of test data. Each group has two positive integers, indicating the first two numbers of the game.
When two zeros are input, the input ends.
Output
For each group of input and output winners, we think they are both top players and each game has made the best choice.
For the specific output format, see the output sample.
Sample Input
34 12
15 24
0 0
Sample output
Xiaoming wins
Xiaohong wins
Ideas:
There are three scenarios:
M is a large number. N is a decimal number.
When M % N = 0: whoever wins
When M/N is equal to 1, there is only one method (m, n)-> (n, m % N)
Who wins when M/N> = 2: Because when (n, m % N) if it is a mandatory state, the attacker can take it as (M % N + n, n), then the loser State is transferred to another person. If (M % N + n, n) is a mandatory defeat
The accessors can be (n, m % N), which is also called the first-hand advantage.
Code:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int main(){ int a,b,tt,t; while(scanf("%d%d",&a,&b)==2&&a+b) { tt=1; while(1) { if(b>a) { t=a; a=b; b=t; } if(a%b==0||a/b>=2) break; tt=!tt; a=a%b; } if(tt==1) printf("xiaoming wins\n"); else printf("xiaohong wins\n"); } return 0;}
Zoj 1913 Euclid's game Game Theory