Description
ICG 游戏,每次可以取走 (i in [1,k]) 颗石子,取最后一颗者胜。判断是否存在必胜策略。
Solution
局面可以用石子数 (n) 描述,则局面的 SG 函数为 (SG(n)= extrm{Mex}_{i=1}^{min(k,n)} SG(n-i))。
显然 (SG(0)=0,SG(1)=1,...,SG(k)=k,SG(k+1)=0,SG(k+2)=1,...,SG(2k+2)=0,...)
于是先手必胜当且仅当 ((k+1) | ot n)
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005;
signed main()
{
int n,k;
cin>>n>>k;
if(n%(k+1))
{
cout<<1;
}
else
{
cout<<2;
}
}