Problem Description:
Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one player must paint a unpainted beads. Whoever is unable to paint in his turn lose
the game. Aekdycoin will take the first move.
Now, they thought this game is too simple, and they want to change some rules. In each turn one player must select a certain number of consecutive unpainted beads to paint. The other rules is The same as the original. Who will win under the rules ?You may assume
that both of them are so clever.
Input:
First line contains T, the number of test cases. Following T line contain 2 integer N, M, indicate the chain has N beads, and each turn one player must paint M consecutive beads. (1 <= N, M <= 1000)
Output:
For each case, print "Case #idx: " first where idx is the case number start from 1, and the name of the winner.
Sample Input:
2
3 1
4 2
Sample Output:
Case #1: aekdycoin
Case #2: abcdxyzk
#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <vector> #include <queue> #include <map> #include <set> #define LL long long using namespace std; const int MAXN = 1000 + 10; int vis[MAXN]; int SG[MAXN]; int m; int mex(int n) { if(SG[n] != -1) return SG[n]; if(n < m) return SG[n] = 0; memset(vis, 0, sizeof(vis)); for(int i=m;i<=n;i++) vis[mex(i-m) ^ mex(n-i)] = 1; for(int i=0;;i++) { if(!vis[i]) { SG[n] = i; break; } } return SG[n]; } int main() { int T, kcase = 1; scanf("%d", &T); while(T--) { int n; scanf("%d%d", &n, &m); if(n < m) { printf("Case #%d: abcdxyzk\n", kcase++); continue; } n -= m; memset(SG, -1, sizeof(SG)); for(int i=0;i<=n;i++) SG[i] = mex(i); if(SG[n] == 0) printf("Case #%d: aekdycoin\n", kcase++); else printf("Case #%d: abcdxyzk\n", kcase++); } return 0; }