Pagini recente » Cod sursa (job #1449269) | Cod sursa (job #3260488) | Cod sursa (job #2572826) | Cod sursa (job #3129114) | Cod sursa (job #1739716)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int gcd(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int tempX, tempY, GCD;
GCD = gcd(b, a%b, tempX, tempY);
x = tempY;
y = tempX - (a / b) * tempY;
return GCD;
}
int main()
{
int noTests;
fin >> noTests;
for (int i = 0; i < noTests; i++)
{
int GCD, a, b, c, x, y;
fin >> a >> b >> c;
GCD = gcd(a, b, x, y);
if (c % GCD != 0)
fout << "0 0" << endl;
else{
fout << x * (c / GCD)<< " " << y * (c / GCD) << endl;
}
}
}