Description
有 (n) 堆石子,每次可以对一堆石子进行操作,如果当前石子是偶数,那么可以选择将这 (2x) 个石子分成 (k) 堆石子数为 (x) 的石子堆,还有一种没有前提的操作是取走当前堆的一个石子,问先手赢还是后手赢。
Solution
若 (x) 为偶数,则 (SG(x)= ext{mex}({ SG(frac x 2)^k, SG(x-1) }))
若 (x) 为奇数,则 (SG(x)= ext{mex} ( { SG(x-1) } ))
先暴力计算出 (x le 4) 的情况,其余满足
(x) 为奇数时,(SG(x)=0)
(x) 为偶数时,若 (k) 也为偶数,则 (SG(x)=1),若 (k) 是奇数,则 (SG(x)= ext{mex} (0,SG(frac x 2)))
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005;
int mex(int x,int y=-1)
{
for(int i=0;i<2;i++)
{
if(x!=i && y!=i) return i;
}
return 2;
}
int a[N],n,k;
int sg(int x)
{
if(x<=4)
{
if(x==0) return 0;
if(x&1)
{
return mex(sg(x-1));
}
else
{
if(k&1) return mex(sg(x/2),sg(x-1));
else return mex(0,sg(x-1));
}
}
else
{
if(x&1)
{
return 0;
}
else
{
if(k&1) return mex(0,sg(x/2));
else return 1;
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin>>n>>k;
int ans=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
ans^=sg(a[i]);
}
cout<<(!ans?"Nicky":"Kevin")<<endl;
}