Pagini recente » Cod sursa (job #90570) | Cod sursa (job #2359012) | Cod sursa (job #2461833) | Cod sursa (job #2300000) | Cod sursa (job #2527311)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid(long long int a, long long int b, long long int &d, long long int &x, long long int &y)
{
if(b == 0)
{
d = a;
x = 1, y = 0;
}
else
{
long long int aux;
euclid(b, a%b, d, x, y);
aux = x;
x = y;
y = aux - (a/b)*y;
}
}
int main()
{
long long int t, a, b, c, div, left, right, i;
fin >> t;
for(i = 0; i < t; i++)
{
fin >> a >> b >> c;
if(a == 0)
{
fout << "0 " << c/b << '\n';
}
else if (b == 0)
{
fout << c/a << " 0" << '\n';
}
else
{
euclid(a, b, div, left, right);
cout << div;
if(c % div == 0)
{
c/=div;
left *= c;
right *= c;
fout << left << ' ' << right << '\n';
}
else
fout << "0 0" << '\n';
}
}
return 0;
}