Pagini recente » Cod sursa (job #1159258) | Cod sursa (job #2719300) | Cod sursa (job #78970) | Cod sursa (job #28816) | Cod sursa (job #3297927)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int T, a, b, c;
int d, x, y;
// a*x + b*y = gcd(a, b)
// b*x1 + (a % b)*y1 = gcd(a, b)
// a % b = a - lower_bound(a / b) * b
// b*x1 + (a - (a / b) * b)*y1 = gcd(a, b)
// a*y1 + b*(x1 - (a / b) * y1) = a*x + b*y
int ExtendedEuclid(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1 = 0, y1 = 0;
int d = ExtendedEuclid(b, (a % b), x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
int main() {
fin >> T;
for (int i = 0; i < T; i++) {
fin >> a >> b >> c;
d = ExtendedEuclid(a, b, x, y);
if (c % d == 0) {
fout << x * (c / d) << " " << y * (c / d) << "\n";
}
else {
fout << "0 0\n";
}
}
return 0;
}