Pagini recente » Cod sursa (job #2378111) | Cod sursa (job #3289156) | Cod sursa (job #3166748) | Cod sursa (job #1445034) | Cod sursa (job #2908106)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("euclid3.in");
ofstream cout("euclid3.out");
int cmmdc_ext(int, int, int&, int&);
int t, a, b, c, d, x, y;
int main() {
cin >> t;
for (; t; t--) {
cin >> a >> b >> c;
d = cmmdc_ext(a, b, x, y);
if (c % d) cout << "0 0\n";
else {
cout << x * c / d << ' ' << y * c / d << '\n';
}
}
return 0;
}
int cmmdc_ext(int a, int b, int& x, int& y) {
if (!b) {
x = y = 1;
return a;
}
int d, x1, y1;
d = cmmdc_ext(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return d;
}