Pagini recente » Cod sursa (job #2622126) | Cod sursa (job #2293194) | Cod sursa (job #3215338) | Cod sursa (job #1842460) | Cod sursa (job #1404156)
#include <fstream>
int ExtendedEuclidean (int a, int b, int &x, int &y)
{
if (!b)
{
x = 1;
y = 0;
return a;
}
int x0, y0, d(ExtendedEuclidean(b,a % b,x0,y0));
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main (void)
{
int t;
std::ifstream input("euclid3.in");
std::ofstream output("euclid3.out");
input >> t;
int a, b, c, x, y, gcd;
while (t)
{
input >> a >> b >> c;
gcd = ExtendedEuclidean(a,b,x,y);
if (c % gcd)
output << "0 0";
else
output << x * (c / gcd) << ' ' << y * (c / gcd);
output.put('\n');
--t;
}
input.close();
output.close();
return 0;
}