| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:用解模线性方程法,还是TL,谁能告诉我还要注意些什么啊?In Reply To:用解模线性方程法,还是TL,谁能告诉我还要注意些什么啊? Posted by:jackie_wyx at 2006-12-08 14:23:53 #include<iostream>
#include<math.h>
using namespace std;
long ext_euclid(long a,long b,long &x,long &y)//求最大公约数
{
long t,d;
if (b==0) {x=1;y=0;return a;}
d=ext_euclid(b,a%b,x,y);
t=x;
x=y;
y=t-a/b*y;
return d;
}
//扩展的欧几里德
long modular_linear_equation_solver(long a,long b,long n)
{
long e,d;
long x,y;
d=ext_euclid(a,n,x,y);
if (b%d>0) return 0;
else
{
e=(x*(b/d))%n;
e=(e+long(fabs(n/d)))%n;
return e;
}
}
int main()
{
long x,y,m,n,l,k;
cin>>x>>y>>m>>n>>l;
k=modular_linear_equation_solver(m-n,y-x+l,l);
if(k)
cout<<k<<endl;
else
cout<<"Impossible"<<endl;
return 0;
}
为什么用扩展的欧几里德算法还是WA啊……
天那……谁帮我看一下啊……
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator