Pagini recente » Cod sursa (job #2468203) | Cod sursa (job #2210923) | Cod sursa (job #728142) | Cod sursa (job #3000750) | Cod sursa (job #2031110)
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
long Euclid(long a, long b)
{
long r;
do
{
r = a%b;
a = b;
b = r;
} while (r);
return r;
}
long EuclidExtins(long a, long b, long&x, long& y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
long x1, y1;
long r = EuclidExtins(b, a%b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return r;
}
int main()
{
int T;
in >> T;
while (T--)
{
long a, b, c, x, y;
in >> a >> b >> c;
long gcd = EuclidExtins(a, b, x, y);
if (c % gcd != 0)
out << "0 0";
else
{
out << x * (c / gcd) << ' ' << y * (c / gcd);
}
out << '\n';
}
}