Pagini recente » Cod sursa (job #469434) | Cod sursa (job #3218272) | Cod sursa (job #2228983) | Cod sursa (job #557140) | Cod sursa (job #1599990)
#include<iostream>
#include<fstream>
using namespace std;
int cmmdex(int a, int b, int& lx, int& ly)
{
int x = 0, y = 1, q;
lx = 1; ly = 0;
int tx, ty, ta;
while (b)
{
q = a / b;
ta = b; b = a%b; a = ta;
tx = x; x = lx - q * x; lx = tx;
ty = y; y = ly - q * y; ly = ly;
}
return a;
}
void main()
{
// a * x + b * y = c
ifstream fin("euclid3.in", ios::in);
ofstream fout("euclid3.out", ios::out);
int T, a, b, c, x, y, d;
fin >> T;
for (int i = 0; i < T; i++)
{
fin >> a;
fin >> b;
fin >> c;
d = cmmdex(a, b, x, y);
if (c % d)
fout << "0 0";
else
fout << x*(c / d) << " " << y*(c / d);
}
}