http://acm.hdu.edu.cn/showproblem.php?pid=1222Wolf and Rabbit
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 6052 Accepted Submission (s): 3032
Problem Descriptionthere 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.
Inputthe 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).
Outputfor each input m n, if safe holes exist, you should output "YES", and Else Output "NO" in a.
Sample Input21 22 2
Sample Outputnoyes
The solving: is to ask whether N and M coprime, GCD (n,m) is equal to 1
Code:
1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5 intGCD (intAintb)6 {7 returnb==0? A:GCD (b,a%b);8 }9 intMain ()Ten { One intN, M; A intT; -Cin>>T; - while(t--) the { -scanf"%d%d",&n,&m); - if(GCD (n,m) = =1) -cout<<"NO"<<Endl; + Elsecout<<"YES"<<Endl; - } + return 0; A}
Wolf and Rabbit