Pagini recente » Cod sursa (job #2811517) | Cod sursa (job #2207770) | Cod sursa (job #2680252) | Cod sursa (job #1224588) | Cod sursa (job #1714819)
#include <fstream>
#define InFile "euclid3.in"
#define OutFile "euclid3.out"
using namespace std;
int euclid (int a, int b, int &x, int &y);
unsigned short int T;
int a, b, c;
int d, x, y;
int i;
int X, Y;
int main ()
{
ifstream fin (InFile);
ofstream fout (OutFile);
fin >> T;
for (i=1; i<=T; i++)
{
fin >> a >> b >> c;
d = euclid(a,b,x,y);
if (c%d)
{
fout << 0 << ' ' << 0;
fout << '\n';
}
else
{
X = x*(c/d);
Y = y*(c/d);
fout << X << ' ' << Y;
fout << '\n';
}
}
fin.close();
fout.close();
return 0;
}
int euclid (int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = euclid(b,a%b,x0,y0);
x = y0;
y = x0 - y0*(a/b);
return d;
}