Pagini recente » Cod sursa (job #2572337) | Diferente pentru schimbare-borland/alternativa intre reviziile 7 si 8 | Monitorul de evaluare | Atasamentele paginii preoji_valoros | Cod sursa (job #1713565)
#include <fstream>
int gcdExt(int a, int b, int& x, int& y) {
if (!b) {
x = 1;
y = 0;
return a;
}
else {
int x0, y0, d;
d = gcdExt (b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
}
int main() {
std::ifstream in{"euclid3.in"};
std::ofstream out{"euclid3.out"};
int T, a, b, c, d, x, y;
for (in >> T; T; --T) {
in >> a >> b >> c;
d = gcdExt(a, b, x, y);
if (c % d) out << "0 0\n";
else {
c /= d;
out << (x * c) << " " << (y * c) << "\n";
}
}
in.close();
out.close();
return 0;
}