Pagini recente » Cod sursa (job #1770567) | Cod sursa (job #3180814) | Cod sursa (job #1410152) | Cod sursa (job #2287483) | Cod sursa (job #2626535)
#include <cstdio>
#include <algorithm>
int gcd(int a, int b, int& x, int& y)
{
if (a == 0)
{
x = 0;
y = 1;
return b;
}
int x_{}, y_{}, d{};
d = gcd(b % a, a, x_, y_);
x = (y_ - (b / a) * x_);
y = x_;
return d;
}
int main(){
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
int t{}, a{}, b{}, c{}, x{}, y{};
scanf("%d", &t);
while (t--)
{
scanf("%d%d%d", &a, &b, &c);
int d = gcd(a, b, x, y);
if (c % d)
printf("0 0\n");
else
printf("%d %d\n", x * (c / d), y * (c / d));
}
return 0;
}