Pagini recente » Cod sursa (job #2558875) | Cod sursa (job #3133861) | Cod sursa (job #2577419) | Cod sursa (job #2229408) | Cod sursa (job #2879264)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int nrec, a, b, c, divizor, x, y;
void euclidnorm(int a, int b, int *d)
{
if (b == 0)
*d = a;
else
euclidnorm(b, a%b, d);
}
void euclidex(int a, int b, int *d, int *x, int *y)
{
if (b == 0)
{
*d = a;
*x = 1;
*y = 0;
}
else
{
int x0, y0;
euclidex(b, a%b, d, &x0, &y0);
*x = y0;
*y = x0 - a/b * y0;
}
}
int main()
{
fin >> nrec;
while (nrec)
{
fin >> a >> b >> c;
euclidex(a, b, &divizor, &x, &y);
if (c % divizor != 0)
fout << 0 << ' ' << 0 << '\n';
else
{
fout << x * c/divizor << ' ' << y* c/divizor << '\n';
}
nrec--;
}
return 0;
}