Pagini recente » Monitorul de evaluare | Cod sursa (job #2990246)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("euclid3.in");
ofstream g ("euclid3.out");
int T, a, b, c, x, y, d;
void Euclid(int a, int b, int &d, int &x, int &y) {
if (b == 0) {
d = a;
x = 1;
y = 0;
}
else {
int x0, y0;
Euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
f >> T;
for (int i = 1; i <= T; i++) {
f >> a >> b >> c;
Euclid(a, b, d, x, y);
if (c % d != 0)
g << 0 << " " << 0 << '\n';
else
g << x * (c / d) << " " << y * (c / d) << '\n';
}
f.close();
g.close();
return 0;
}