Pagini recente » Cod sursa (job #47208) | Cod sursa (job #2492242) | Cod sursa (job #122359) | Cod sursa (job #198537) | Cod sursa (job #2643518)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void extendedGCD(long a, long b, long* x, long* y, long* r)
{
if (b == 0)
{
*x = 1;
*y = 0;
*r = a;
}
else
{
long x0, y0;
extendedGCD(b, a % b, &x0, &y0, r);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main()
{
int T;
fin >> T;
while (T--)
{
long a, b, c, x, y, gcd;
fin >> a >> b >> c;
extendedGCD(a, b, &x, &y, &gcd);
if (c % gcd != 0)
{
fout << 0 << " " << 0 << '\n';
continue;
}
fout << (x * c) / gcd << " " << (y * c) / gcd << '\n';
}
fin.close();
fout.close();
return 0;
}