Pagini recente » Cod sursa (job #2787839) | Cod sursa (job #1369650) | Cod sursa (job #1181383) | Cod sursa (job #1723871) | Cod sursa (job #2440737)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void gcdExt(int a, int b, int &d, int&x, int &y)
{
if(b == 0)
d = a, x = 1, y = 0;
else
{
int x0, y0;
gcdExt(b, a % b, d, x0, y0);
x = y0;
y = x0 - a / b * y0;
}
}
int main()
{
int a, b, c, d, x, y, T;
fin >> T;
for (size_t i = 0; i < T; i++)
{
fin >> a >> b >> c;
gcdExt(a, b, d, x, y);
cout <<a<<" "<<b<<" "<< c<< " " << d << " " << x << " " << y << endl;
if(c % d)
fout << "0 0 \n";
else
fout << x * (c / d) << " " << y * (c / d) << "\n";
}
return 0;
}