Pagini recente » Cod sursa (job #1635178) | Cod sursa (job #2628717) | Cod sursa (job #854155) | Cod sursa (job #1280771) | Cod sursa (job #808486)
Cod sursa(job #808486)
#include <cstdio>
#include <algorithm>
using namespace std;
inline int next_int() {
int d;
scanf("%d", &d);
return d;
}
template<class T> pair<T, T> egcd(T a, T b) {
pair<T, T> x(0, 1), y(1, 0), g(a, b);
while (g.second != 0) {
T q = g.first / g.second;
g = pair<T, T> (g.second, g.first % g.second);
x = pair<T, T> (x.second - q * x.first, x.first);
y = pair<T, T> (y.second - q * y.first, y.first);
}
return pair<T, T> (x.second, y.second);
}
template<class T> T gcd(T a, T b) {
while (b != 0) {
T t = a % b;
a = b;
b = t;
}
return a;
}
int main() {
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
int T = next_int();
while (T--) {
int a = next_int();
int b = next_int();
int c = next_int();
int g = gcd(a, b);
pair<int, int> eg = egcd(a, b);
if (c % g == 0) {
printf("%d %d\n", eg.first * c / g, eg.second * c / g);
} else {
printf("0 0\n");
}
}
return 0;
}