Pagini recente » Cod sursa (job #3358328) | Cod sursa (job #2003230) | Cod sursa (job #3358223) | Cod sursa (job #3358440) | Cod sursa (job #3358200)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
// gasim x si y astfel incat a*x + b*y = d unde d = cmmdc(a, b)
long long euclid(long long a, long long b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
long long x1, y1;
long long d = euclid(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return d;
}
int main()
{
int t;
fin >> t;
for (int i = 0; i < t; i++)
{
long long a, b, c, x, y;
fin >> a >> b >> c;
long long d = euclid(a, b, x, y);
if (d < 0)
{
d = -d;
x = -x;
y = -y;
}
if (d == 0 || c % d != 0)
{
fout << 0 << " " << 0 << "\n";
}
else
{
long long k = c / d;
fout << x * k << " " << y * k << "\n";
}
}
return 0;
}