http://acm.hdu.edu.cn/showproblem.php?pid=4764
可选范围是【1到n-1】
可以看出 先选n-1必胜,因为下一个人必选大于等于n的数,则选到【n-k-1到n-2】为必败态,因为下一个人就选到了n-1。
同理n-k-2也是必胜态,因为下一个人必会落入【n-k-1到n-2】这个必败态,因此n-1、 n-1-(k+1)等 循环节为k+1的一些数构成必胜态
即使如果n-1与k+1构成整除关系则为必败态,否则必胜
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
const int N=21234;
int fa[N];
int find(int x)
{
if (x==fa[x]) return x;
else return fa[x]=find(fa[x]);
}
vector<int> g[N];
int isson[N];
int x[N],y[N];
char ss[N];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
if (!n&&!m) break;
if ((n-1)%(m+1)==0)
{
printf("Jiang\n");
}
else
printf("Tang\n");
}
}