[HDU] [1222] Wolf and Rabbit

Problem Description

Loading...

Problem Analysis

Because it’s a cyclic process
so if the greatest common divisor of the two numbers is 1
the wolf can catch the rabbit

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include<stdio.h>
int gcd(int a,int b) {
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main() {
    int T;
    scanf("%d",&T);
    while(T--) {
        int n,m;
        scanf("%d %d",&n,&m);
        printf("%s\n",gcd(n,m)==1?"NO":"YES");
    }
    return 0;
}

Loading...