Pagini recente » Cod sursa (job #1610891) | Cod sursa (job #902306) | Cod sursa (job #1890538) | Cod sursa (job #1761393) | Cod sursa (job #3225446)
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int cmmdc(int a, int b, int &x, int &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}else {
int ans = cmmdc(b, a % b, x, y);
int xPrim = x;
int yPrim = y;
x = yPrim;
y = xPrim - (a / b) * yPrim;
return ans;
}
}
int main() {
int t;
in >> t;
for(int q = 1;q <= t;q++) {
int a, b, c, x, y, d;
in >> a >> b >> c;
d = cmmdc(a, b, x, y);
if(c % d == 0) {
out << 1LL * x * (c / d) << ' ' << 1LL * y * (c / d) << '\n';
}else {
out << "0 0\n";
}
}
return 0;
}