Pagini recente » Cod sursa (job #3351424) | Cod sursa (job #3326606) | Cod sursa (job #3349576) | Cod sursa (job #3318351) | Cod sursa (job #3357254)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
long long extended_euclid(long long a, long long b, long long& x, long long& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long x1, y1;
long long d = extended_euclid(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return d;
}
int main() {
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int T;
if (!(fin >> T)) return 0;
while (T--) {
long long a, b, c;
fin >> a >> b >> c;
if (a == 0 && b == 0) {
if (c == 0) fout << "0 0\n";
else fout << "0 0\n";
continue;
}
int sign_a = (a < 0) ? -1 : 1;
int sign_b = (b < 0) ? -1 : 1;
long long x0, y0;
long long d = extended_euclid(abs(a), abs(b), x0, y0);
if (c % d != 0) {
fout << "0 0\n";
}
else {
long long x = x0 * (c / d);
long long y = y0 * (c / d);
x *= sign_a;
y *= sign_b;
fout << x << " " << y << "\n";
}
}
fin.close();
fout.close();
return 0;
}