Players, Stan and Ollie, play, starting with and natural numbers. Stan, the first player, subtracts any positive multiple of the of the lesser of the numbers from the greater of the RS, provided the resulting number must be nonnegative. Then Ollie, the second player, does the same with the and the resulting numbers, then Stan, etc, alternately, until one Playe R is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players could start with (25,7):
25 7
11 7
4 7
4 3
1 3
1 0
An Stan wins.
Inputthe input consists of a number of lines. Each line contains the positive integers giving the starting of the game. Stan always starts. Outputfor each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play PERFEC tly. The last line of input contains, zeroes and should not be processed.
Sample Input
0 0
Sample Output
Stan wins
Ollie wins
If a% b = = 0 Initiator win
If a >= 2b then if a% b,b is a must, the initiator can change the number to a% B, b if it is a win state can change the number to a% B + B, B and the hand can only operate into a% B, b initiator win
If a < 2b has been reduced until the winning state is present
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream >
#include <limits>
#include <stack>
#include <queue>
#include <cmath>
#define INF 1000005
using namespace std;
int a, B;
int main ()
{
while (scanf ("%d%d", &a,&b)! = EOF && (A | | b)) {
if (a < b)
swap (b);
if (! ( A% b) | | A >= 2 * b) {
printf ("Stan wins\n");
}
else{
int k = 0;
while (A < 2 * b && a% b) {
a = B;
if (a < b) {
swap (b);
}
++k;
}
if (k% 2) {
printf ("Ollie wins\n");
}
else{
printf ("Stan wins\n");
}}} return 0;
}