# Wolf and Rabbit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5929    Accepted Submission(s): 2977

Problem Description
There is a hill with n holes around. The holes are signed from 0 to n-1.

A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into the hole every m holes. For example, m=2 and n=6, the wolf will get into the holes which are signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she will survive. So we call these holes the safe holes.

Input
The input starts with a positive integer P which indicates the number of test cases. Then on the following P lines,each line consists 2 positive integer m and n(0<m,n<2147483648).

Output
For each input m n, if safe holes exist, you should output "YES", else output "NO" in a single line.

Sample Input
2 1 2 2 2

Sample Output
NO YES

Author
weigang Lee

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int exGcd(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;
y=0;
return a;// 此时a是最开始（a,b）的最大公约数，那么  gcd（a,b）*1+ 0*0=gcd(a,b),肯定对的，在这里，我认为，y可以为任何值都对
}

int d=exGcd(b,a%b,y,x);
y-=a/b*x;
return d;//返回最大公约数
}
int main()
{
int n,m,t,x,y;
cin>>t;
while(t--)
{
cin>>n>>m;
if(exGcd(n,m,x,y)==1)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
}
}


• 本文已收录于以下专栏：

## HDOJ 1222 Wolf and Rabbit(判断互质，水)

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
• zwj1452267376
• 2016年04月05日 17:28
• 311

## HDU 1222 Wolf and Rabbit（数论）

• weizhuwyzc000
• 2015年10月06日 08:18
• 494

## 【杭电oj】1222 - Wolf and Rabbit（GCD）

• wyg1997
• 2016年07月18日 17:10
• 170

## Wolf and Rabbit （HDU 1222）

• jxust_tj
• 2014年05月01日 18:03
• 827

## 【杭电1222】Wolf and Rabbit

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
• better_space
• 2016年08月04日 14:47
• 194

## HDU 1222 Wolf and Rabbit

• murmured
• 2013年12月26日 13:49
• 837

## wolf and rabbit

There is a hill with n holes around. The holes are signed from 0 to n-1.  A rabbit must hid...
• xinxiaxindong
• 2017年01月29日 19:04
• 76

## Wolf and Rabbit

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
• evi__
• 2014年02月10日 22:20
• 468

## ACM-简单题之Wolf and Rabbit——hdu1222

Wolf and Rabbit Problem Description There is a hill with n holes around. The holes are signed from ...
• lx417147512
• 2013年11月15日 21:17
• 1559

## HDU1222:Wolf and Rabbit

Problem DescriptionThere is a hill with n holes around. The holes are signed from 0 to n-1.A rabbit ...
• zyang008
• 2011年03月30日 14:59
• 1538

举报原因： 您举报文章：Wolf and Rabbit（欧几里得） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)