模线性方程
#include
#include
typedef struct _EUCLID_ITEM{
int d;
int x;
int y;
/*
_EUCLID_ITEM(int arg1,int arg2,int arg3){
d=arg1;x=arg2;y=arg3;
}*/
}EUCLID_ITEM;
EUCLID_ITEM extended_euclid(int a,int b){
EUCLID_ITEM tmp,aResult;
if(b==0){
EUCLID_ITEM aResult={a,1,0};
return aResult;
}
tmp=extended_euclid(b,a%b);
aResult.d=tmp.d;
aResult.x=tmp.y;
aResult.y=tmp.x-(a/b)*tmp.y;
return aResult;
}
void modular_linear_equation_solver(int a,int b,int n){
EUCLID_ITEM t=extended_euclid(a,n);
int d=t.d;
int x0;
if(b % d ==0){
x0 = t.x * (b/d) %n; //x0的值可能为负,怎么办?
for(int i=0;i