Cod sursa(job #1701472)
| Utilizator | Data | 13 mai 2016 10:29:45 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <fstream>
using namespace std;
ifstream in ("euclid3.in");
ofstream out ("euclid3.out");
int euclid (int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = euclid (b, a % b, x0, y0);
x = y0;
y = x0 - a / b * x;
return d;
}
int main()
{
int a, b, c, t, i, d, x, y;
in >> t;
for(i = 1; i <= t; i ++)
{
in >> a >> b >> c;
d = euclid (a, b, x, y);
if (c % d != 0) out << "0 0\n";
else out << x * c / d << " " << y * c / d << "\n";
}
return 0;
}
