Pagini recente » Cod sursa (job #380040) | Profil mariav | Cod sursa (job #222443) | Cod sursa (job #2584966) | Cod sursa (job #1689546)
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int t, a, b, c, d, x, y;
int euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1, y = 0;
return a;
}
int xx = 0, yy = 0, c;
c = euclid(b, a%b, xx, yy);
x = yy;
y = xx - (a/b)*yy;
return c;
}
int main()
{
for (f >> t; t; t--)
{
f >> a >> b >> c;
x = 0, y = 0;
d = euclid(a, b, x, y);
if (c%d != 0)
g << "0 0\n";
else
g << (c/d)*x << " " << (c/d)*y << '\n';
}
return 0;
}