Pagini recente » Cod sursa (job #2230055) | Cod sursa (job #3129183) | Cod sursa (job #2631715) | Cod sursa (job #1210487) | Cod sursa (job #2255959)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int ExtendedEuclid(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int x0, y0, d = ExtendedEuclid(b, a % b, x0, y0);
x = x0;
y = x0 - (a / b) * y0;
}
int main()
{
int T;
fin >> T;
int a, b, c, x, y;
for(int i = 1; i <= T; i++)
{
fin >> a >> b >> c;
int gcd = ExtendedEuclid(a, b, x, y);
if(c % gcd == 0)
fout << x * (c / gcd) << ' ' << y * (c / gcd) << '\n';
else
fout << "0 0\n";
}
return 0;
}