【題解】Codeforces 603C. Lieges of Legendre

【題目敘述】http://codeforces.com/contest/603/problem/C

#include <iostream>
using namespace std;
 
int n, k, a, ans;
 
int even(int x){
    if (x <= 2) return x;
    if (x % 2) return 0;
    return 1;
}
int odd(int x){
    if (x == 0) return 0;
    if (x == 1) return 1;
    if (x == 2) return 0;
    if (x == 3) return 1;
    if (x == 4) return 2;
    if (x >= 5 && x % 2) return 0;
    if (odd(x/2) == 1) return 2;
    return 1;
}
 
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> a;
        if (k % 2) ans ^= odd(a);
        else ans ^= even(a);
    }
    if (!ans) cout << "Nicky\n";
    else cout << "Kevin\n";
}
分享本文 Share with friends