Pagini recente » Cod sursa (job #3262649) | Cod sursa (job #984187) | Cod sursa (job #1215230) | Cod sursa (job #3286631) | Cod sursa (job #165698)
Cod sursa(job #165698)
#include <stdio.h>
int t;
int GCD(int a, int b, int &x, int &y);
int main()
{
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
scanf("%d", &t);
while ( t )
{
int a, b, c, x, y, d;
scanf("%d %d %d", &a, &b, &c);
d = GCD(a, b, x, y);
if ( c % d != 0 ) printf("0 0\n");
else printf("%d %d\n", x *(c/d), y*(c/d));
t--;
}
return 0;
}
int GCD(int a, int b, int &x, int &y)
{
if ( b == 0 )
{
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = GCD(b, a % b, x0, y0 );
x = y0;
y = x0 - (a/b) * y0;
return d;
}