Pagini recente » Cod sursa (job #2447727) | Cod sursa (job #502636) | Cod sursa (job #767014) | Cod sursa (job #2191247) | Cod sursa (job #2715565)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream o("euclid3.out");
long long euclid(long long a, long long b, long long *x, long long *y)
{
if (b == 0)
{
*x = 1;
*y = 0;
return a;
}
else
{
long long x0, y0, d;
d = euclid(b, a % b, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
return d;
}
}
int main()
{
long long n, a, b, x, y, d, c;
f >> n;
for (long long 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";
}
}