Pagini recente » Cod sursa (job #1828486) | Cod sursa (job #2056626) | Cod sursa (job #1120197) | Cod sursa (job #286694) | Cod sursa (job #1331385)
#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;
int d = gcd(b, a%b, &x0, &y0);
*x = y0;
*y = x0 - (a / b)*(y0);
return d;
}
}
int main()
{
ifstream inFile("euclid3.in");
ofstream outFile("euclid3.out");
int T;
inFile >> T;
for (T; T; T--)
{
int a, b, c;
inFile >> a >> b >> c;
int x, y, d;
d = gcd(a, b, &x, &y);
if (c%d)
{
outFile << 0 << " " << 0;
if (T > 1)
outFile << endl;
}
else
{
outFile << x*(c / d) << " " << y*(c / d);
if (T > 1)
outFile << endl;
}
}
}