Pagini recente » Cod sursa (job #2952925) | Cod sursa (job #2155452) | Cod sursa (job #2816215) | Cod sursa (job #2451868) | Cod sursa (job #879495)
Cod sursa(job #879495)
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
void euclid(int a, int b, int &d, int &x, int &y)
{
if (b == 0)
{
d = a;
x = 1;
y = 0;
} else {
int x0, y0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
int a, b, c, t, d, x, y;
in >> t;
for (int i = 0; i < t; i++)
{
in >> a >> b >> c;
euclid(a, b, d, x, y);
if (c % d == 0) out << (c / d) * x << ' ' << (c / d) * y << '\n';
else out << 0 << ' ' << 0 << '\n';
}
return 0;
}