Pagini recente » Cod sursa (job #1164346) | Cod sursa (job #1789047) | Cod sursa (job #1981108) | Cod sursa (job #2273635) | Cod sursa (job #2782955)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int euclidExtins(int a, int b, int& x, int& y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int x0, y0;
int cmmdc = euclidExtins(b, a % b, x0, y0);
x = y0;
y = x0 - a / b * y0;
return cmmdc;
}
int main()
{
int t;
fin >> t;
while (t--)
{
int a, b, c, x, y;
fin >> a >> b >> c;
int cmmdc = euclidExtins(a, b, x, y);
if (c % cmmdc == 0)
{
fout << x * (c / cmmdc) << ' ' << y * (c / cmmdc) << '\n';
}
else
{
fout << "0 0\n";
}
}
}