time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either:
- Remove a single cow from a chosen non-empty pile.
- Choose a pile of cows with even size 2·x (x > 0), and replace it with k piles of x cows each.
The player who removes the last cow wins. Given n, k, and a sequence a1, a2, ..., an, help Kevin and Nicky find the winner, given that both sides play in optimal way.
Input
The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers, a1, a2, ... an (1 ≤ ai ≤ 109) describing the initial state of the game.
Output
Output the name of the winning player, either "Kevin" or "Nicky" (without quotes).
Examples
input
Copy
2 1 3 4
output
Copy
Kevin
input
Copy
1 2 3
output
Copy
Nicky
Note
In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other.
题意:有n堆石子,每次操作选一堆石子,如果它为奇数,则拿走一个石子,如果为偶数,则可以拿走一个石子,也可以将其变为k堆,每堆石子数量为x/2
题解:推导一下,再打表找规律
//#include<bits/stdc++.h>
//#include<unordered_map>
//#include<unordered_set>
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a, b) memset(a,b,sizeof(a))
#define lson l, mid, node<<1
#define rson mid + 1, r, node<<1|1
const int INF = 0x3f3f3f3f;
const int O = 1e6;
const int mod = 1e9+7;
const int maxn = 9e5 +5;
const double PI = acos(-1.0);
const double E = 2.718281828459;
const double eps = 1e-8;
int sg[maxn];
int n, k;
// 打表
void init(){
sg[0] = 0;
for(int i=1; i<maxn; i++) {
if(i & 1) sg[i] = (sg[i-1] == 0);
else {
int mex1 = sg[i-1];
int mex2 = k & 1 ? sg[i/2] : 0; // 如果为偶数,分为k堆异或和一定为0,奇数则为sg[x/2]
for(int j=0; j<3; j++) if(mex1 != j && mex2 != j) {
sg[i] = j; break;
}
}
}
}
// 结合sg表找规律
int get_SG(int x) {
if(x == 0) return 0;
if(x == 1) return 1;
if(k & 1) {
if(x == 2) return 0;
if(x == 3) return 1;
if(x == 4) return 2;
if(x & 1) return 0;
else return get_SG(x/2) == 1 ? 2 : 1;
}
else {
if(x == 2) return 2;
if(x & 1) return 0 ;
else return 1;
}
}
int main(){
scanf("%d%d", &n, &k);
//init();
int ans = 0;
for(int i=0; i<n; i++) {
int x; scanf("%d", &x);
ans ^= get_SG(x);
}
printf(ans ? "Kevin" : "Nicky");
return 0;
}