Pagini recente » Cod sursa (job #138768) | Cod sursa (job #3196892) | Cod sursa (job #3150688) | Monitorul de evaluare | Cod sursa (job #1402053)
#include <fstream>
#include <iostream>
using namespace std;
ifstream F("euclid3.in");
ofstream G("euclid3.out");
int t,a,b,c,d;
int cmmdc(int x,int y)
{
return y == 0 ? x : cmmdc(y,x%y);
}
void euclid(int a,int &x,int b,int &y,int c)
{
if ( b == 0 )
{
x = 1;
y = 0;
return;
}
int x0 = 0 , y0 = 0;
euclid(b,x0,a%b,y0,c);
x = y0;
y = x0 - (a/b) * y0;
}
int main()
{
F>>t;
for (int i=1;i<=t;++i)
{
F>>a>>b>>c;
d = cmmdc(a,b);
if ( c % d )
G<<"0 0\n";
else
{
int x = 0, y = 0;
euclid(a,x,b,y,d);
G<<x*(c/d)<<' '<<y*(c/d)<<'\n';
}
}
}