Test instructions: The topic gives two positive numbers a, B, each operation can reduce the large number of small number of integer times. When a number becomes 0, it ends.
Who first reduced one of the numbers to a 0 win. Ask who can win. Stan is the initiator.
Idea: Suppose a>=b, if a%b = = 0, then certainly is the initiator wins. (Click Open link) if a>=2*b. Then that person must know whether a%b,b is winning or losing.
State. If it is a fail state, the initiator will be a A, a a%b,b, then the initiator must win. If it is a winning state, the initiator will change a, b into a%b+b,b. Then the opponent only turns these two numbers into
A%b,b, the initiator wins. If it is b<a<2*b then there is only one way: to become a-b,b (this time 0<a-b<b). So go on and see who is going to face the top of the winning state. The
In the face of B < A <2*b state, the first step to go down. Until the face of a a%b==0 | | The state of a >=2*b.
Code:
Import Java.util.Arrays;
Import Java.util.Scanner;
public class Main {public
static void Main (string[] args) {
Scanner sc = new Scanner (system.in);
int a, B;
while (Sc.hasnext ()) {
a = Sc.nextint ();
b = Sc.nextint ();
if (a = = 0 && b = = 0) break
;
if (a < b) {
int t = A;
A = b;
b = t;
}
int win = 0;
while (b! = 0) {
if (a = = B | | A >= 2 * b) break
;
A-= B;
int t = A;
A = b;
b = t;
Win ^= 1;
}
System.out.println (win = = 0?) "Stan wins": "Ollie wins");}}}