Pagini recente » Cod sursa (job #955237) | Cod sursa (job #440296) | Cod sursa (job #686624) | Cod sursa (job #1093311) | Cod sursa (job #3234620)
#include <iostream>
#include <fstream>
using namespace std;
struct eucl
{
int d, x, y;
};
eucl euclidExtins(int a, int b)
{
if (b == 0)
{
eucl ret;
ret.d = a;
ret.x = 1;
ret.y = 0;
return ret;
} else
{
eucl var = euclidExtins(b, a % b);
eucl ret;
ret.d = var.d;
ret.x = var.y;
ret.y = var.x - (a / b) * var.y;
return ret;
}
}
int main()
{
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int T;
fin >> T;
while (T--) {
int a, b, c;
fin >> a >> b >> c;
eucl result = euclidExtins(abs(a), abs(b));
if (c % result.d != 0) {
fout << "0 0" << endl;
} else {
int x = result.x * (c / result.d);
int y = result.y * (c / result.d);
if (a < 0) x = -x;
if (b < 0) y = -y;
fout << x << " " << y << endl;
}
}
fin.close();
fout.close();
return 0;
}