Pagini recente » Cod sursa (job #3310201) | Cod sursa (job #463620) | Cod sursa (job #1662708) | Cod sursa (job #743971) | Cod sursa (job #3320239)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
long cmmdc(long x, long y)
{
unsigned int r;
if (x < y)
{
swap(x, y);
}
while (x % y)
{
r = x % y;
x = y;
y = r;
}
return y;
}
void euclid(int a, int b, long *d, long *x, long *y)
{
if (b == 0)
{
*d = a;
*x = 1;
*y = 0;
}
else
{
long x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main(void)
{
short T, i;
long a, b, c, e, f;
fin >> T;
for (i = T; i; i--)
{
fin >> a >> b >> c;
if(c%cmmdc(a,b))
{
fout << "0 0" << endl;
}
else
{
euclid(a,b,&c,&e,&f);
fout << e << ' ' << f << endl;
}
}
return 0;
}