Pagini recente » Cod sursa (job #2673677) | Cod sursa (job #1916922) | Cod sursa (job #3326260) | Cod sursa (job #2477998) | Cod sursa (job #3340854)
#include <fstream>
int bezout_gcd(int a, int &x, int b, int &y)
{
int r_x, r_y, d;
if (b == 0) {
x = 1;
y = 0;
d = a;
} else {
d = bezout_gcd(b, r_x, a % b, r_y);
x = r_y;
y = r_x - (a / b) * r_y;
}
return d;
}
int main()
{
int n;
std::ifstream fin("euclid3.in");
std::ofstream fout("euclid3.out");
fin >> n;
for (int a, x, b, y, d, c, i = 0; i < n; ++i) {
fin >> a >> b >> c;
d = bezout_gcd(a, x, b, y);
if (c % d)
fout << "0 0\n";
else
fout << x * (c / d) << ' ' << y * (c / d) << '\n';
}
fin.close();
fout.close();
return 0;
}