Cod sursa(job #1970413)
Utilizator | Data | 19 aprilie 2017 12:20:11 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int sub(const int a, const int b, int & x, int & y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = sub(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main()
{
int t, a, b, c, d, x, y;
f>>t;
while(t--) {
f>>a>>b>>c;
d = sub(a, b, x, y);
if (c % d)
g<<"0 0\n";
else g<<x * (c / d)<<' '<<y * (c / d)<<'\n';
}
return 0;
}