Pagini recente » Cod sursa (job #1241582) | Cod sursa (job #3287962) | Cod sursa (job #339004) | Cod sursa (job #230767) | Cod sursa (job #610258)
Cod sursa(job #610258)
#include <fstream.h>
long euclid (long a, long b, long &x, long &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
long x0, y0, d;
d = euclid (b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main ()
{
short T, i;
long a, b, c, x, y, d;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
fin >> T;
for (i = 0; i < T; i++)
{
fin >> a >> b >> c;
d = euclid (a, b, x, y);
if (c % d) fout << "0 0\n";
else fout << x * (c / d) << " " << y * (c / d) << "\n";
}
fin.close ();
fout.close ();
return 0;
}