Pagini recente » Cod sursa (job #77936) | Cod sursa (job #840148) | Cod sursa (job #2712341) | Cod sursa (job #150602) | Cod sursa (job #2580446)
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int a, b, c, d, x, y, t, i;
int cmmcdExtins(int a, int b, int& x, int& y)
{
if (!b)
{
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = cmmcdExtins(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main()
{
f >> t;
for (i = 1; i <= t; i++)
{
f >> a >> b >> c;
d = cmmcdExtins(a, b, x, y);
if (c % d)
g << "0 0" << "\n";
else
g << x * (c / d) << " " << y * (c / d) << "\n";
}
return 0;
}