Pagini recente » Cod sursa (job #2374977) | Cod sursa (job #2235734) | Cod sursa (job #1957869) | Cod sursa (job #345970) | Cod sursa (job #1919962)
#include <iostream>
using namespace std;
int Gcd(int a, int b, int& x, int& y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
int aux_x, aux_y;
int r = Gcd(b, a % b, aux_x, aux_y);
// aux_x * b + aux_y * (a - a / b * b) = r
// aux_b * b + aux_y * a - aux_y * (a / b) * b
// aux_y * a + b * (aux_x + aux_y * (a / b))
x = aux_y;
y = aux_x + aux_y * (a / b);
return r;
}
int main() {
#ifdef INFOARENA
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
#endif
int T;
cin >> T;
while(T--) {
int a, b, c;
cin >> a >> b >> c;
int x, y;
int d = Gcd(a, b, x, y);
if(c % d)
cout << "0 0\n";
else {
x *= c / d;
y *= c / d;
cout << x << ' ' << y << '\n';
}
}
}