Pagini recente » Cod sursa (job #273647) | Cod sursa (job #2917969) | Cod sursa (job #2881619) | Cod sursa (job #2853730) | Cod sursa (job #156427)
Cod sursa(job #156427)
#include <stdio.h>
int a, b, c, d, x, y;
int gcdext(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = gcdext(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b) * y0;
return d;
}
int main()
{
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out","w",stdout);
int T;
scanf("%d ", &T);
for (; T>0; --T)
{
scanf("%d %d %d ", &a, &b, &c);
d = gcdext(a, b, x, y);
if (c % d != 0)
{
printf("0 0\n");
}
else
printf("%d %d\n", x * (c/d), y * (c/d));
}
return 0;
}