Pagini recente » Cod sursa (job #1682190) | Cod sursa (job #248697)
Cod sursa(job #248697)
#include<fstream.h>
ifstream f("euclid3.in");
ofstream g("euclid3.out");
/*int gcd( int a, int b, int &X, int &Y)
{
int X0 , Y0 , d;
if (b == 0)
{
X = 1;
Y = 0;
return a;
}
d = gcd( b, a % b, X0, Y0 );
X = Y0;
Y = X0 - (a / b) * Y0;
return d;
}
int main()
{
int t;
long a , b , c , d , x , y;
f>>t;
int i;
for(i = 1 ; i <= t ; i++)
{
f>>a>>b>>c;
d = gcd(a , b , x , y);
if(c%d != 0)
g<<"0 0"<<"\n";
else
g<<x*(c/d)<<" "<<y*(c/d)<<"\n";
}
f.close();
g.close();
return 0;
} */
int euclid_extins(int a , int b , int &X , int &Y)
{
int X0 , Y0 , d;
if(!b)
{
X = 1;
Y = 0;
return a;
}
d = euclid_extins(b , a%b , X0 , Y0);
X = Y0;
Y = X0 - (a/b) * Y0;
return d;
}
int main()
{
int n , i , a , b , c , d , x , y;
f>>n;
for(i = 1 ; i <= n ; i++)
{
f>>a>>b>>c;
d = euclid_extins(a , b , x , y);
if(c%d)
g<<"0 0\n";
else
g<<x * (c/d)<<' '<<y*(c/d)<<'\n';
}
g.close();
return 0;
}