Pagini recente » Cod sursa (job #2702519) | Cod sursa (job #442733) | Cod sursa (job #792076) | Cod sursa (job #1363997) | Cod sursa (job #2715560)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream o("euclid3.out");
int euclid(int a, int b, int *x, int *y)
{
if (b == 0)
{
*x = 1;
*y = 0;
return a;
}
else
{
int x0, y0, d;
d = euclid(b, a % b, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
return d;
}
}
int main()
{
int n, a, b, x, y, d, c;
f >> n;
for (int i = 0; i < n; i++)
{
f >> a >> b >> c;
d = euclid(a, b, &x, &y);
cout << x << " " << y << " " << c << " " << d << "\n";
if (c % d != 0)
o << "0 0";
else
o << x * c / d << " " << y * c / d;
o << "\n";
}
}