Pagini recente » Cod sursa (job #1754077) | Cod sursa (job #986058) | Cod sursa (job #1468110) | Cod sursa (job #1111259) | Cod sursa (job #718736)
Cod sursa(job #718736)
#include <fstream>
using namespace std;
int Euclid(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
else
{
int d, x0, y0;
d = Euclid(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
return d;
}
}
int main()
{
int a, b, c, t, d, x, y;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
f>>t;
while (t)
{
t--;
f>>a>>b>>c;
d = Euclid(a, b, x, y);
if (c%d)
g<<"0 0\n";
else
g<<x*(c/d)<<" "<<y*(c/d)<<"\n";
}
f.close();
g.close();
return 0;
}