Pagini recente » Cod sursa (job #929283) | Cod sursa (job #2335094) | Cod sursa (job #950308) | Cod sursa (job #1904477) | Cod sursa (job #290206)
Cod sursa(job #290206)
#include<fstream.h>
int k;
int euclid(int &x, int &y, int a, int b)
{
if (b==0) {
x=1;
y=0;
return a;
}
else {
k=euclid (x,y,b,a%b);
int *h=new int;
*h=y;
y=x-y*(a/b);
x=*h;
delete h;
return k;
}
}
int main()
{
int t,a,b,x,y,c,d;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
f>>t;
for (;t>0;t--)
{
f>>a>>b>>d;
c=euclid(x,y,a,b);
if (d%c==0) g<<x*(d/c)<<' '<<y*(d/c)<<"\n";
else g<<0<<' '<<0<<"\n";
}
f.close();
g.close();
return 0;
}