[NYOJ] [1143] Xiao Ke's Worry

Problem Description

小珂的苦恼
Time limit: 1000 msMemory limit: 256 MB

Description

Xiao Ke is a middle school student, and she is very troubled right now because her teacher assigned her a troublesome homework. Can you help her? The problem information is as follows.

Given the linear Diophantine equation ax+by=n, determine whether this equation has integer solutions, where x and y are unknowns, a, b, and n are all integers and none of them is zero, and 0<a,b,n<2^16-1.

Input

The first line contains an integer 0<n<=1000000, indicating that there are n groups of test data. Each of the following lines contains three integers, which are a, b, and n respectively.

Output

If there exist integers x and y such that the equation has a solution, output “Yes”; otherwise output “No”.

Sample Input

1
2
3
2
2 4 2
3 9 7

Sample Output

1
2
Yes
No

Source

Xiao Ke’s Trouble - NYOJ

Problem Analysis

The condition for the linear Diophantine equation to have integer solutions is
$n\%gcd(a,b)==0$

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

Loading...