Pagini recente » Cod sursa (job #2540436) | Cod sursa (job #67772) | Cod sursa (job #1634817) | Cod sursa (job #19607) | Cod sursa (job #1610245)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int euclid(int a, int b, int &x, int &y);
int main()
{
int a, b, c, d, cv, x, y, i, t;
fin >> t;
for (i = 1; i <= t; i++)
{
fin >> a >> b >> c;
d = euclid(a, b, x, y);
if (c % d) fout << "0 0\n";
else
{
cv = c / d;
fout << x * cv << ' ' << y * cv << '\n';
}
}
return 0;
}
int euclid(int a, int b, int& x, int& y)
{
int d, x1, y1;
if (!b)
{
x = 1;
y = 0;
return a;
}
else
{
d = euclid(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
}