Pagini recente » Cod sursa (job #2649984) | Cod sursa (job #3189097) | Cod sursa (job #2080945) | Cod sursa (job #2945897) | Cod sursa (job #3136240)
#include <iostream>
#include <fstream>
using namespace std;
ifstream intrare("euclid3.in");
ofstream iesire("euclid3.out");
int gcd_extins(long int a, long int b, long int &x, long int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long int x0, y0;
long int d = gcd_extins(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main() {
long int n, a, b, c, x0, y0, d;
intrare >> n;
for (int i = 0; i < n; i++) {
intrare >> a >> b >> c;
d = gcd_extins(a, b, x0, y0);
if (c % d)
iesire << 0 << " " << 0 << '\n';
else
iesire << x0 * (c / d) << " " << y0 * (c / d) << '\n';
}
return 0;
}