Pagini recente » Cod sursa (job #47172) | Cod sursa (job #1054863) | Cod sursa (job #1841575) | Cod sursa (job #1892908) | Cod sursa (job #3250634)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid_extins(int a, int b, int &d, int &x, int &y)
{
if (!b)
{
d = a;
x = 1;
y = 0;
return;
}
int x1, y1;
euclid_extins(b, a % b, d, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
}
int main()
{
int a, b, c, t, x, y, d;
fin >> t;
while (t > 0)
{
fin >> a >> b >> c;
x = y = d = 0;
euclid_extins(a, b, d, x, y);
if((c % d) != 0)
fout << "0 0" << '\n';
else
fout << x * (c / d) << ' ' << y * (c / d) << '\n';
}
return 0;
}