Pagini recente » Cod sursa (job #3204767) | Cod sursa (job #3170845) | Cod sursa (job #1126073)
#include <iostream>
#include <fstream>
using namespace std;
void gcd( int a, int b, int &d, int &x, int &y )
{
if ( !b )
{
d = a;
x = 1;
y = 0;
}
else
{
int x0, y0;
gcd( b, a % b, d, x0, y0 );
x = y0;
y = x0 - ( a / b ) * y0;
}
}
int T, a, b, c, d, x, y;
int main()
{
ifstream f("euclid3.in");
ofstream g("euclid3.out");
f >> T;
while ( T-- )
{
f >> a >> b >> c;
gcd( a, b, d, x, y );
if ( c % d )
{
g << "0 0\n";
}
else
{
g << x * ( c / d ) << " " << y * ( c / d ) << "\n";
}
}
return 0;
}