Pagini recente » Cod sursa (job #2418101) | Cod sursa (job #1010411) | Cod sursa (job #2202434)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void ReadFunction();
void EuclidExtins(int a, int b, int& x, int& y, int& d);
int a[101], b[101], c[101], n;
int x, y, d;
int main()
{
ReadFunction();
for (int i = 1; i <= n; ++i)
{
EuclidExtins(a[i], b[i], x, y, d);
if (c[i] % (d) == 0)
{
fout << x * (c[i] / d) << ' ' << y * (c[i] / d) << '\n';
}
else
fout << 0 << ' ' << 0 << '\n';
}
}
void ReadFunction()
{
fin >> n;
for (int i = 1; i <= n; ++i)
fin >> a[i] >> b[i] >> c[i];
}
void EuclidExtins(int a, int b, int& x, int& y, int& d)
{
if (b == 0)
{
d = a;
x = 1;
y = 0;
}
else
{
int x0, y0;
EuclidExtins(b, a % b, x0, y0, d);
x = y0;
y = x0 - (a / b) * y0;
}
}