Cod sursa(job #1490886)
| Utilizator | Data | 24 septembrie 2015 13:00:40 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.64 kb |
#include <fstream>
inline void gcd (int a, int b, int& x, int& y, int& d) {
if (0 == b) {
x = 1;
y = 0;
d = a;
}
else {
int x0, y0;
gcd (b, a % b, x0, y0, d);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main() {
int T, a, b, c, d, x, y;
std::ifstream in {"euclid3.in"};
std::ofstream out {"euclid3.out"};
for (in >> T; T; --T) {
in >> a >> b >> c;
gcd (a, b, x, y, d);
if (c % d) {
out << "0 0\n";
}
else {
c /= d;
out << (x * c) << ' ' << (y * c) << '\n';
}
}
return 0;
}
