Pagini recente » Cod sursa (job #3293104) | Cod sursa (job #3253205) | Cod sursa (job #2176860) | Cod sursa (job #143377) | Cod sursa (job #3263238)
#include <iostream>
#include <fstream>
int euclid(int a, int b, int& x, int& y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
else {
int x0, y0;
int d = euclid(b, a%b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
}
int main()
{
int n;
// a, b and c are the coefficients in the followin equation: ax + by = c
// d is the gcd(a, b)
int a, b, c, d;
std::ifstream fin("euclid3.in");
std::ofstream fout("euclid3.out");
fin >> n;
for (; n; n--)
{
fin >> a >> b >> c;
int x, y;
d = euclid(a, b, x, y);
if (c % d != 0)
{
fout << "0 0\n";
continue;
}
fout << x * (c / d) << " " << y * (c / d) << '\n';
}
return 0;
}