Pagini recente » Cod sursa (job #1390442) | Cod sursa (job #2377540) | Cod sursa (job #2883296) | Cod sursa (job #1544785) | Cod sursa (job #2348419)
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int ExtendedEuclid(int a, int b, int &x, int &y) {
if (b == 0 ) {
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = ExtendedEuclid(b, a %b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main() {
int T;
in >> T;
for (int i = 0; i < T; ++i) {
int a, b, c, d, x, y;
in >> a >> b >> c;
d = ExtendedEuclid(a, b, x, y);
if (c % d) {
out << "0 0\n";
} else {
out << x * (c / d) << ' ' << y * (c / d) << '\n';
}
}
return 0;
}