#include <iostream>
#include <vector>
#include <cmath>
#include “BigNum.h”
using namespace std;
//扩展欧几里得算法(最大公约数及逆元)
void ExtendedEuclid(int d,int f)
{
int q,x1,x2,x3,y1,y2,y3,t1,t2,t3;
x1=1; x2=0; x3=f;
y1=0; y2=1; y3=d;
while(1){
if(y3==0){
cout << “gcd(“<<d<<“,”<<f<<“):”<<x3<<endl;
break;
}
if(y3==1){
if(y2<0) y2 += f;
cout << “gcd(“<<d<<“,”<<f<<“):”<<y3;
cout <<“/n”<<d<<“-1mod”<<f<<“:”<<y2<<endl;
break;
}
q = x3/y3;
t1=x1-q*y1; t2=x2-q*y2; t3=x3-q*y3;
x1=y1; x2=y2; x3=y3;
y1=t1; y2=t2; y3=t3;
}
}
void main()
{
cout <<“清翔兔@2006/n扩展欧几里得算法/n请先输入一个数(小):”;
int a,b;
cin >> a;
cout<<“请再输入一个数(mod):”;
cin >>b;
ExtendedEuclid(a,b);
}
// down exe file: http://i1984.com/x/page53_ex4-4.exe