Pagini recente » Cod sursa (job #1028286) | Cod sursa (job #967986) | Cod sursa (job #3170982) | Cod sursa (job #26697) | Cod sursa (job #786026)
Cod sursa(job #786026)
#include <iostream>
#include <fstream>
std::ifstream f("euclid3.in");
std::ofstream g("euclid3.out");
void euclid(int a, int b, int &d, int &x, int &y)
{
if (b == 0) {
x = 1;
y = 0;
d = a;
}
else {
int x0, y0;
euclid(b, a % b, d, x0, y0);
y = x0 - (a / b) * y0;
x = y0;
}
}
int main()
{
int noTests;
int a, b, c, d, x, y;
f >> noTests;
for (int t = 0; t < noTests; ++t) {
f >> a >> b >> c;
euclid(a, b, d, x, y);
if (c % d == 0) {
g << (x * (c / d)) << ' ' << (y * (c / d)) << '\n';
}
else {
g << "0 0\n";
}
}
return 0;
}