Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser of the two numbers from the greater of the two numbers, provided that the resulting number must be nonnegative. Then Ollie, the second player, does the same with the two resulting numbers, then Stan, etc., alternately, until one player is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players may start with (25,7): 
         25 7

         11 7

          4 7

          4 3

          1 3

          1 0

an Stan wins.
Input
The input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.
Output
For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly. The last line of input contains two zeroes and should not be processed.
Sample Input
34 12
15 24
0 0
Sample Output
Stan wins
Ollie wins

题意:两个数中较大的数取余较小的数(辗转相除的过程)直到其中一个数为0 时结束,注意:每次的选择都是最完美的选择。

假设两数分别为a , b;通过交换使得a 一直大于b;

分三种情况:

1,a 是 b 的倍数 即a%b = 0 时 ,Stan 先开始 则 Stan必胜。

2.b < a < 2*b时 ,必须通过一步一步来得出谁胜谁负 , 因此在每进行一步时可以用flag = !flag 来确定最后谁胜谁负 , 或用ans++通过判断ans的奇偶来判断,最终得到答案。

3.a >= 2*b时 , 那么Stan可以通过选择来使自己胜 .

	32 7-----S-------1
		
	25 7----O-------2

        11 7-----S-----3

        4 7-----O------4

        4 3-----S-------5

        1 3----O------6

        1 0------S-------7

如上:Stan 可以直接跳到第三步 , 然后一步一步的向下进行最终胜利 ,即只要a>2*b时 , Stan就可以拥有两种选择 , 可以奇数或偶数倍的跳到某一步使对方没有选择权 。

以下是代码:

#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
	int n , m;
	while(~scanf("%d %d" , &n , &m) && (n + m))
	{
			if(n < m)
			{
				swap(n , m);
			}
			int flag = 0;
		while(m)
		{
				if(n % m == 0 || n/m >= 2)
				{
					break;
				}
				n = n - m;
			if(n < m)
			{
				swap(n , m);
			}
						flag = !flag;
		}
			if(!flag)
					{
						cout << "Stan wins" << endl;
					
					}
					else
					{
						cout <<"Ollie wins" << endl;
				
					}
	}
	return 0;
}