http://acm.hdu.edu.cn/showproblem.php?pid=2104
这道题看很久啊,意思是n个人围成一个圈,大家玩丢手帕游戏,手帕藏在某一个人的箱子里,Haha来找,每一次他都会跳过m-1个人。问你Haha是不是一定能找到手帕。因为Haha找的次数是无限的,可以永远找下去,所以,只要他能把所有的人都找一遍就一定能找到。但按照他的这种找法,如果n和m不互质的话,不互质就会出现某些人是永远不会找。所以看一下 n和m的最大公约数就行了
代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m),n!=-1&&m!=-1)
{
if(gcd(n,m)==1) puts("YES");
else puts("POOR Haha");
}
return 0;
}