Pagini recente » Cod sursa (job #3292145) | Cod sursa (job #2643152)
#include <iostream>
#include <fstream>
using namespace std;
const long N_MAX = 2000000000;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void extendedGCD(long a, long b, long* x, long* y, long* r) {
if (b == 0) {
*x = 1;
*y = 0;
*r = a;
}
else {
long x0, y0;
extendedGCD(b, a % b, &x0, &y0, r);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main() {
int T;
fin >> T;
while (T--) {
long a, b, c, x, y, gcd;
fin >> a >> b >> c;
extendedGCD(a, b, &x, &y, &gcd);
if (c % gcd != 0) {
fout << 0 << " " << 0 << '\n';
continue;
}
fout << (x * c) / gcd << " " << (y * c) / gcd << '\n';
}
fin.close(); fout.close();
return 0;
}