Pagini recente » Cod sursa (job #1705897) | Statistici Tudor Patricia (patriciat) | Cod sursa (job #3296757) | Profil deniros14 | Cod sursa (job #1932634)
#include <fstream>
#include <string>
const std::string NO_SOL = "0 0\n";
int gcd(int a, int b, int& x, int& y)
{
if ( b == 0 )
{
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = gcd(b, a % b, x0, y0);
x = x0;
y = y0 - (a/b) * y0;
return d;
}
int main()
{
std::ifstream fin("euclid3.in");
std::ofstream fout("euclid3.out");
int t;
for ( fin >> t; t; t--)
{
int a, b, c;
fin >> a >> b >> c;
int d, x, y;
d = gcd(a,b,x,y);
if ( c % d )
{
fout << NO_SOL;
}
else
{
fout << x * (c/d) << ' ' << y * (c/d) << '\n';
}
}
return 0;
}