Description
There is a hill with n holes around. The holes is 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 was the one signed with 0. Then he'll get into the hole every m holes. For example, m=2 and n=6, the Wolf would get into the holes which is signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she'll 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, the If safe holes exist, you should output "YES", and Else Output "NO" in a.
Sample Input
21 22 2
Sample Output
Noyes Problem Solving idea: The topic is let us beg greatest common divisor, if two number of greatest common divisor equals 1, output no, otherwise output yes. We use the greatest common divisor method to find the code of the program:
#include <iostream>using namespace std;int gcd (int a,int b) { return b==0? A:GCD (b,a%b);} int main () {int T;cin>>t;while (t--) {int m,n;cin>>m>>n;int p=gcd (m,n), if (p==1) cout<< "NO" < <endl;elsecout<< "YES" <<ENDL;} return 0;}
ACM Divide-and-greatest common divisor method (for the sake of)