-
Notifications
You must be signed in to change notification settings - Fork 0
/
spoj_cequ.cpp
68 lines (57 loc) · 1.04 KB
/
spoj_cequ.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
void read(int &a)
{
scanf("%d",&a);
}
void read(int &a,int &b)
{
scanf("%d %d",&a,&b);
}
void read(int &a,int &b,int &c)
{
scanf("%d %d %d",&a,&b,&c);
}
//r extended Euclidean Algorithm
int gcdExtended(int a, int b, int &x, int &y)
{
// Base Case
if (a == 0)
{
x = 0;
y = 1;
return b;
}
int x1, y1; // To store results of recursive call
int gcd = gcdExtended(b%a, a, x1, y1);
// Update x and y using results of recursive
// call
x = y1 - (b/a) * x1;
y = x1;
return gcd;
}
// Driver Program
int main()
{
int x, y;
int a,c ,b,t;
read(t);
int k=0;
while(t--)
{k++;
read(a,b,c);
int g = gcdExtended(a, b, x, y);
// printf("gcd(%d, %d) = %d,%d,%d", a, b, g,x,y);
if(c%g == 0){
printf("Case %d: Yes\n",k);
continue;}
if(g==1)
{
if(c%a ==0 || c%b==0){
printf("Case %d: Yes\n",k);
continue;}
}
else
printf("Case %d: No\n",k);
}
return 0;
}