求解模线性方程
来源:互联网 发布:视频同步同声翻译软件 编辑:程序博客网 时间:2024/04/29 11:27
#include using namespace std; struct sgcd sgcd gcd(int a,int b) } //---35x=10(mod 50)
{
int d;
int x;
int y;
};
{
sgcd temp,tempp;
if (b==0)
{
temp.d=a;
temp.x=1;
temp.y=0;
return temp;
}
tempp=gcd(b,a%b);
temp.d=tempp.d;
temp.x=tempp.y;
temp.y=tempp.x-a/b*tempp.y;
return temp;
void mod_l_eq(int a,int b,int n)
{
sgcd mydata;
mydata=gcd(a,n);
int x0=0;
if(b%mydata.d==0)
{
x0=(mydata.x*b/mydata.d)%n;
for(int i=0;i
//---print it,if the value low than 0,add n to it
cout<<(x0+i*(n/mydata.d)>0 ? x0+i*(n/mydata.d):x0+i*(n/mydata.d)+n)%n<
}
}
int main()
{
mod_l_eq(35,10,50);
system("pause");
return 0;
}