-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#16_CEQU.txt
50 lines (28 loc) · 1.03 KB
/
#16_CEQU.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Linear Diophantine Equations
A Diophantine equation is a polynomial equation, usually in two or more unknowns, such that only the integral solutions are required.
An Integral solution is a solution such that all the unknown variables take only integer values.
Given three integers a, b, c representing a linear equation of the form : ax + by = c.
Determine if the equation has a solution such that x and y are both integral values.
For linear Diophantine equation equations, integral solutions exist if and only if, the GCD of coefficients of the two variables divides the constant term perfectly.
In other words the integral solution exists if, GCD(a ,b) divides c.
#include<stdio.h>
gcd(int m,int n){
if(n==0)
return m;
else
return gcd(n,m%n);
}
int main(){
int a,b,c,t,g,e=1;
scanf("%d",&t);
while(t--){
scanf("%d %d %d",&a,&b,&c);
g=gcd(abs(a),abs(b));
if(c%g==0)
printf("Case %d: Yes\n",e);
else
printf("Case %d: No\n",e);
e++;
}
return 0;
}