Pagini recente » Cod sursa (job #2843697) | Cod sursa (job #3201288) | Cod sursa (job #207505) | Cod sursa (job #2497554) | Cod sursa (job #2669573)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int x0, y0;
int rez = euclid(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b) * y0;
return rez;
}
int main()
{
int n;
f >> n;
for (int t = 1; t <= n; t++)
{
int a, b, c;
int x, y;
f >> a >> b >> c;
int d = euclid(a, b, x, y);
cout << x << ' ' << y << ' '<< d << '\n';
if (c%d != 0)
g << "0 0\n";
else
g << 1LL * x * c/d << ' ' << 1LL * y * c/d << '\n';
}
return 0;
}