Pagini recente » Cod sursa (job #3253646) | Cod sursa (job #150876) | Cod sursa (job #1452145) | Cod sursa (job #2736080) | Cod sursa (job #1215634)
#include <fstream>
int euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int x0, y0, res;
res = euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return res;
}
int main()
{
std::ifstream in("euclid3.in");
std::ofstream out("euclid3.out");
int nOp;
in >> nOp;
for (int i = 0; i < nOp; i++)
{
int a, b, c, x, y;
in >> a >> b >> c;
int res = euclid(a, b, x, y);
if (c % res)
{
out << 0 << ' ' << 0 << '\n';
}
else
{
out << x * (c / res) << ' ' << y * (c / res) << '\n';
}
}
in.close();
out.close();
return 0;
}