Pagini recente » Cod sursa (job #2157156) | Cod sursa (job #3267093) | Cod sursa (job #445709) | Cod sursa (job #2748410) | Cod sursa (job #1221113)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int T, a, b, c, x, y, cmmdc, V[10000];
void PreCalcul(int aa, int bb)
{
int rr;
while (bb)
{
V[++V[0]] = aa / bb;
rr = aa % bb;
aa = bb;
bb = rr;
}
cmmdc = aa;
}
void Solve()
{
while (V[0])
{
int aux = x;
x = y;
y = aux - V[V[0]] * y;
V[0]--;
}
}
int main()
{
fin >> T;
for (int i=1; i<=T; i++)
{
fin >> a >> b >> c;
PreCalcul(a, b);
x = 1;
y = 0;
Solve();
if (c % cmmdc)
{
fout << 0 << ' ' << 0 << '\n';
}
else
{
fout << x * (c / cmmdc) << ' ' << y * (c / cmmdc) << '\n';
}
}
fout.close();
return 0;
}