Pagini recente » Cod sursa (job #161167) | Cod sursa (job #3200150) | Cod sursa (job #1945487) | Cod sursa (job #3037327) | Cod sursa (job #3133268)
#include <bits/stdc++.h>
using namespace std;
const string FNAME = "euclid3.";
ifstream fin(FNAME + "in");
ofstream fout(FNAME + "out");
void euclid(int a, int b, int &gcd, int &x, int &y) {
if (!b) {
gcd = a;
x = 1;
y = 0;
} else {
int xaux, yaux;
euclid(b, a % b, gcd, xaux, yaux);
x = yaux;
y = xaux - (a/b) * yaux;
}
}
int main() {
int t;
fin >> t;
for (int a, b, c, gcd, x, y; t--;) {
fin >> a >> b >> c;
euclid(a, b, gcd, x, y);
if (c % gcd) {
fout << "0 0\n";
} else {
fout << x * (c/gcd) << ' ' << y * (c/gcd) << '\n';
}
}
fout.close();
return 0;
}