Pagini recente » Cod sursa (job #3288242) | Cod sursa (job #2691871) | Cod sursa (job #1340609) | Cod sursa (job #1408538) | Cod sursa (job #2499417)
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int tests;
int a, b, c;
int extendedEuler(int a, int b, int& resultX, int& resultY) {
if (b == 0) {
// 1 * gcd(a, b) + 0 * 0 = gcd(a, b)
resultX = 1; resultY = 0;
return a;
}
int nextX, nextY;
int d = extendedEuler(b, a % b, nextX, nextY);
resultX = nextY;
resultY = nextX - nextY * (a / b);
return d;
}
int main() {
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> tests;
for (int test_no = 1; test_no <= tests; test_no++) {
cin >> a >> b >> c;
int resultA, resultB;
int cmmdc = extendedEuler(a, b, resultA, resultB);
if (c % cmmdc) {
cout << "0 0\n";
} else {
cout << resultA * (c / cmmdc) << " " << resultB * (c / cmmdc) << "\n";
}
}
return 0;
}