Cod sursa(job #1005081)
Utilizator | Data | 4 octombrie 2013 03:28:13 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
using namespace std;
void cmmdc(int a, int b, int &x, int &y, int &d) {
if (b == 0) {
d = a;
x = 1;
y = 0;
} else {
int u, v;
cmmdc(b, a%b, u, v, d);
x = v;
y = u - (a/b) * v;
}
}
int main()
{
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int n, a, b, c, d, x, y;
for (fin >> n; n; --n) {
fin >> a >> b >> c;
cmmdc(a, b, x, y, d);
if (c % d)
fout << "0 0\n";
else
fout << x * (c/d) << ' ' << y * (c/d) << '\n';
}
return 0;
}