Pagini recente » Cod sursa (job #2655425) | Cod sursa (job #1663667) | Cod sursa (job #624446) | Cod sursa (job #2244882) | Cod sursa (job #2669570)
#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 << x * c/d << ' ' << y * c/d << '\n';
}
return 0;
}