Pagini recente » Cod sursa (job #2803870) | Cod sursa (job #3156011) | Clasament dfghjk | Cod sursa (job #1953710) | Cod sursa (job #2939165)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclidExt(int a, int b, int &d, int &x, int &y) {
if (b == 0) {
d = a;
x = 1;
y = 0;
return;
}
int q = a/b, x2, y2;
euclidExt(b, a - q*b, d, x2, y2);
x = y2;
y = x2 - q*y2;
}
int main() {
int t;
fin >> t;
for (int i = 0; i < t; i++) {
int a, b, c;
fin >> a >> b >> c;
int x, y, d;
euclidExt(a, b, d, x, y);
if (c % d == 0) {
int q = c/d;
fout << x*q << ' ' << y*q << '\n';
}
else
fout << "0 0\n";
}
return 0;
}