Pagini recente » info-arena 2.0 | info-arena 2.0 | Cod sursa (job #1197885) | Cod sursa (job #2610821) | Cod sursa (job #2118951)
#include<iostream>
#include<fstream>
using namespace std;
int gcd(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
else
{
int x0, y0, d;
d = gcd(b, a%b, x0, y0);
x = y0;
y = x0 - (a / b)*y0;
return d;
}
}
int main()
{
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int n = 0;
f >> n;
for (int i = 0; i < n; i++)
{
int a, b, c, d;
int x = 0, y = 0;
f >> a >> b >> c;
d = gcd(a, b, x, y);
if (c%d)
g << "0 0" << endl;
else
g << x * (c / d) << " " << y*(c / d) << endl;
}
f.close();
g.close();
return 0;
}