Cod sursa(job #2127125)
| Utilizator | Data | 10 februarie 2018 12:45:36 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
void euclidextins(int a, int b, int &x, int &y, int &d)
{
if (!b)
{
x = 1;
y = 0;
d = a;
}
else
{
int x0, y0;
euclidextins(b, a%b, x0, y0, d);
x = y0;
y = x0 - (a / b)*y0;
}
}
int main()
{
int n, a, b, c, d, x, y;
in >> n;
while (n)
{
in >> a >> b >> c;
euclidextins(a, b, x, y, d);
if (c%d == 0)
{
out << x * (c / d) << ' ' << y * (c / d) << '\n';
}
else out << 0 << ' ' << 0 << '\n';
n--;
}
return 0;
}