Pagini recente » Cod sursa (job #439576) | Monitorul de evaluare | Cod sursa (job #452888) | Cod sursa (job #733186) | Cod sursa (job #3203910)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid_extended(int a, int b, int c, int& x, int& y, int& d) {
if (b == 0) {
d = a;
x = c / a;
y = 0;
} else {
int x0, y0;
euclid_extended(b, a % b, c, x0, y0, d);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main() {
int T;
fin >> T;
for (int t = 0; t < T; ++t) {
int a, b, c;
fin >> a >> b >> c;
int x, y, d;
euclid_extended(a, b, c, x, y, d);
if (c % d == 0) {
fout << x << " " << y << "\n";
} else {
fout << "0 0\n";
}
}
return 0;
}