Cod sursa(job #936430)
Utilizator | Data | 7 aprilie 2013 05:24:03 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
int d, x, y, tmp;
void gcd(int a, int b) {
if (a == 0) {
d = b;
x = 0;
y = 1;
}
else {
gcd(b%a, a);
tmp = x;
x = y - (b/a)*x;
y = tmp;
}
}
int main() {
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int n;
fin >> n;
int a, b, c;
for (; n > 0; --n) {
fin >> a >> b >> c;
gcd(a,b);
if (c%d == 0) fout << c/d*x << ' ' << c/d*y << '\n';
else fout << "0 0\n";
}
return 0;
}