对于任意状态(x,y)如果x>=2*y则先手必胜。原因很简单,假设m=x%y,如果(y,m)是必胜状态,则先手只用取到y+m,由于y<y+m<2*y所以一定可行,那么将对手置于必败态,必胜,而如果(y,m)是必败状态,先手只用取到m就好了,还是必胜而如果2*y>x>y只有一种决策,就是取y个,但是时间复杂度已经可以很轻松的承受了
#include<cstdio>
#include<cstring>
#include<iostream>
#define LL unsigned long long
#define sswap(a,b) (a^=b^=a^=b)
using namespace std;
LL n,m,T,pos;
char s[3][20]={"Stan wins","Ollie wins"};
int main(){
scanf("%llu",&T);
while(T--){
scanf("%llu%llu",&n,&m);
if(n<m)sswap(n,m);
int pos=1;
while(m>0){
pos^=1;
if(n>=m*2)break;
n-=m;
sswap(n,m);
}
printf("%s\n",s[pos]);
}
return 0;
}