#include<iostream>
using namespace std;
class xyd
{
public:
int x ;
int y ;
int d ;
};
// function Euclid
xyd * Euclid_extra(int a,int b);
// function main
int main()
{
int a,b,i = 0;
xyd * R = new xyd;
int max;
while( i<55 )
{
a = rand()%10;
b = rand()%10;
if( a<b )
{
max = b;
b = a;
a = max;
}
R = Euclid_extra(a,b) ;
if( R )
{
cout<<"a="<<a<<",b="<<b<<",R->x="<<R->x<<",R->y="<<R->y<<",d="<<R->d<<endl;
cout<<"a*x + b*y = "<<R->d<<endl;
}
i++;
}
system("pause");
return 0;
}
// function Euclid
xyd * Euclid_extra(int a,int b)
{
if( a <= 0 || b < 0 )
{
cout<<"exception of Euclid_extra input"<<endl ;
return NULL ;
}
else
{
int max;
if( a<b )
{
max = b;
b = a;
a = max;
}
xyd * R = new xyd;
if(b == 0)
{
R -> x = 1;
R -> y = 0;
R -> d = a;
return R;
}
else
{
R = Euclid_extra(b,a%b);
}
xyd * R2 = new xyd;
R2 -> x = R -> y;
R2 -> y = (R -> x) - ( (a/b) * (R->y) );
R2 -> d = R->d;
return R2;
}
}