Pagini recente » Cod sursa (job #524737) | Cod sursa (job #1596526) | Cod sursa (job #3254415) | Cod sursa (job #2356099) | Cod sursa (job #3246565)
#include <fstream>
using namespace std;
ifstream cin("euclid3.in");
ofstream cout("euclid3.out");
int d, x, y;
void euclid_extins(int a, int b) {
if (b == 0) {
d = a, x = 1, y = 0;
return ;
}
else {
int x2 = 1, x1 = 0, y2 = 0, y1 = 1;
while (b > 0) {
int q = a / b;
int r = a % b;
x = x2 - (q * x1);
y = y2 - (q * y1);
a = b;
b = r;
x2 = x1;
x1 = x;
y2 = y1;
y1 = y;
}
d = a, x = x2, y = y2;
}
}
int main() {
int t;
cin >> t;
for (int i = 1; i <= t; ++ i) {
int a, b, c;
cin >> a >> b >> c;
euclid_extins(a, b);
if ((c % d) != 0)
cout << 0 << ' ' << 0 << '\n';
else
cout << x * (c / d) << ' ' << y * (c / d) << '\n';
}
return 0;
}