Pagini recente » Cod sursa (job #1193679) | Cod sursa (job #1608484) | Cod sursa (job #410187) | Cod sursa (job #1546288) | Cod sursa (job #1255772)
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int a,b,c,t,d,x,y;
int euclid(int a,int b,int &x,int &y)
{
int d=0,xp=0,yp=0;
if(b==0)
{
x=1;
y=0;
return a;
}
else
{
d=euclid(b,a%b,xp,yp);
x=yp;
y=xp-(a/b)*yp;
return d;
}
}
int main()
{
f>>t;
for(int i=1;i<=t;i++)
{
f>>a>>b>>c;
d=euclid(a,b,x,y);
if(c%d!=0)
g<<"0 0"<<'\n';
else
{
g<<x*(c/d)<<" "<<y*(c/d)<<'\n';
}
}
return 0;
}