The SG -defined functions, can be found when y <x <2y time, SG (X, Y) = [SG (XY, Y) = 0] , i.e., there must be both a 0 , so there SG (x + ky, Y) MEX = (0, ......)> 0 .
In other words, a state for SG (X, Y) (X> Y) , if $ x \ ge 2y $ is the winning state, and when x <2y direct continuation judging SG (xy, y) of this state can be. The total time complexity requirements similar GCD , i.e. $ O (LOG_ {n-2}) $ .
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 int a,b; 5 int main(){ 6 while (scanf("%d%d",&a,&b)!=EOF){ 7 if (a<b)swap(a,b); 8 if (!a)return 0; 9 int ans=0; 10 while (b){ 11 if ((a-b>b)||(a%b==0))break; 12 a-=b; 13 swap(a,b); 14 ans^=1; 15 } 16 if (ans)printf("Ollie wins\n"); 17 else printf("Stan wins\n"); 18 } 19 }