Pagini recente » Cod sursa (job #910488) | Cod sursa (job #1038847) | Cod sursa (job #2155918) | Cod sursa (job #1047432) | Cod sursa (job #1376860)
#include <fstream>
int ExtendedEuclidean (int a, int b, int &x, int &y)
{
if (!b)
{
x = 1;
y = 0;
return a;
}
int x1, y1, gcd(ExtendedEuclidean(b,a % b,x1,y1));
x = y1;
y = x1 - (a / b) * y1;
return gcd;
}
int main (void)
{
std::ifstream input("euclid3.in");
int t;
input >> t;
std::ofstream output("euclid3.out");
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;
}