Cod sursa(job #1561000)
| Utilizator | Data | 3 ianuarie 2016 16:09:52 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <fstream>
void gcd (int x, int y, int& d, int& a, int& b) {
if (0 == y) {
d = x;
a = 1;
b = 0;
}
else {
int a0, b0;
gcd (y, x % y, d, a0, b0);
a = b0;
b = a0 - (x / y) * b0;
}
}
int main() {
int T, x, y, a, b, c, d;
std::ifstream in{"euclid3.in"};
std::ofstream out{"euclid3.out"};
for (in >> T; T; --T) {
in >> x >> y >> c;
gcd(x, y, d, a, b);
if (c % d) {
out << "0 0\n";
}
else {
out << ((c / d) * x) << " " << ((c / d) * y) << "\n";
}
}
return 0;
}
