Pagini recente » Cod sursa (job #2588925) | Cod sursa (job #2903600) | Cod sursa (job #2117321) | Cod sursa (job #1221657) | Cod sursa (job #1256406)
#include <fstream>
using namespace std;
ifstream is("euclid3.in");
ofstream os("euclid3.out");
void Euclid(int a, int b, int & d, int &x, int &y );
int a, b, c, d, x, y;
int t;
int main()
{
is >> t;
while ( t-- )
{
is >> a >> b >> c;
Euclid(a, b, d, x, y );
if ( c % d )
os << "0 0\n";
else
os << x * (c/d) << ' ' << y * (c/d)<< '\n';
}
is.close();
return 0;
}
void Euclid(int a, int b, int &d, int &x, int &y )
{
if ( b == 0 )
{
d = a;
x = 1;
y = 0;
return;
}
int x0, y0;
Euclid(b, a%b, d, x0, y0 );
x = y0;
y = x0 - (a/b) * y0;
}