Conversion to the problem of judging coprime with Euclidean algorithm D-wolf and Rabbit

Source: Internet
Author: User
Tags gcd

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 Description: A wolf on a ring road, a total of n holes in the ring road, the wolf from the beginning of every m hole to search once, ask if there is no safe hole has output yes, otherwise output no idea: determine whether M and N is coprime, coprime there is no safe hole, otherwise there is a safe hole reason: M and N of least common multiple t = M*i = n*j; The distance is t when the wolf back to the original point, start the next cycle of the search, each cycle of the hole traversed by the assumption that the long distance has not been all holes searched for a certain search, because the next search to the place and the original must be repeated m and n coprime time just t=m*n, a week                period, just traversing n holes if M and n is not coprime, then I must be less than n, that is, traversing I (less than m) is enough for a period, certainly not convenient to finish n a hole ah only when M and N coprime, the wolf in a cycle to search all the holes In fact, Judge Coprime is very simple, the key is can think of this problem is actually a judgment coprime problem
#include <stdio.h>#defineLL Long LongLL gcd (intAintb) {    return(b = =0) ? A:GCD (b, a%b);}intMain () {BOOLFlag;    LL T; scanf ("%lld", &t);  while(t--) {LL m, l; Flag=1; scanf ("%lld%lld", &m, &l); if(GCD (M, l) = =1) printf ("no\n"); Elseprintf ("yes\n"); }    return 0;}

Conversion to the problem of judging coprime with Euclidean algorithm D-wolf and Rabbit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.