Pagini recente » Cod sursa (job #1314672) | Cod sursa (job #1170420)
#include <fstream>
using namespace std;
inline int Cmmdc( int a, int b, int &x, int &y )
{
int x0, y0, d;
if (b == 0)
{
x = 1;
y = 0;
return a;
}
d = Cmmdc( b, a % b, x0, y0 );
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main()
{
int i, nrTeste, a, b, c, d, x, y;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
fin >> nrTeste;
for (i = 1; i <= nrTeste; ++i)
{
fin >> a >> b >> c;
d = Cmmdc(a, b, x, y);
if (c % d != 0)
fout << "0 0\n";
else
{
x = x * c / d;
y = y * c / d;
fout << x << " " << y << "\n";
}
}
return 0;
}