This topic, if not find the direction, really a bit confused. But if you look in the right direction, AC is a matter of minutes. The answer is to see if N and M have the number of conventions other than 1.
Simple proof: Set N and M greatest common divisor not 1, assuming p. N and M can always be a number multiplied by the form of K, may wish to make n=a*k,m=b*k (temporarily do not know what is the use); So the first time the wolf traversed the hole numbered 0,m,2m ... (assuming that these holes are numbered within n-1), assuming that the wolf I will be more than n-1, then this should be i*m, but i*m>n-1, so this hole number is (i*m)%n, but, but, but (i*m)%n=i*b*k-a*k= (i* B-A) *k. (A*k,b*k comes in handy) [if (b<a<2b), A%b=a-b], description of the hole number or a multiple of k ah ... But p>1, so that the wolf can not traverse all the caves, then the rabbit is a place to hide.
The main topic: There are N caves, numbered 0~n-1, now a wolf from the mouth of the No. 0, every m-1 (here I have a little doubt about the original question, the original question is every m holes, but the case is m-1 only to) a hole to catch the rabbit, ask the rabbit finally can escape a robbery. For example, there are n=6 a hole, the number is 0, 1, 2, 3, 4, 5, the wolf every m-1=1 a hole to catch the rabbit, then the wolf into the cave is 0, 2, 4, 0, 2, 4 ... (infinite loop). If rabbits hide in holes 1, 3 and 5th, they are safe.
Sample Input
2//Number of test cases
1 2//m and N
2 2
Sample Output
NO
YES
#include <iostream>using namespacestd;intT,m,n;intgcdintAintb//This greatest common divisor function is best remembered, very important.{ returnb==0? A:GCD (b,a%b);}intMain () {CIN>>T; while(t--) {cin>>m>>N; if(GCD (m,n) = =1) cout<<"no\n"; Elsecout<<"yes\n"; } return 0;}
2016HUAS_ACM Summer Camp 4F-Number theory