[poj2505]A multiplication game
首先有SG(k)=mex(SG(k/2),SG(k/3)……SG(k/9)),SG(0)=0,通过打表可以发现当$n\in[1,1]\cup [10,18]\cup [163,324]……$,规律大概就是$[18^{k-1}+1,18^{k}/2]$时SG的值为0(即必败),那么只需要判断一下n是否能满足这个区间即可。
1 #include<cstdio> 2 long long n,t; 3 int main(){ 4 while (scanf("%lld",&n)!=EOF){ 5 t=1; 6 while (t<n)t*=18; 7 if (t/2<n)printf("Ollie wins.\n"); 8 else printf("Stan wins.\n"); 9 } 10 }