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:你只有一个CASE...In Reply To:我用欧几里有点疑问,请高手帮忙看看 Posted by:ghostxp at 2006-08-18 10:47:21 > 我用的欧几里德解同余模算术方法,和通过的程序对比过,答案一样,速度快,但始终无法AC,哪位高手能指点一下: > > #include <stdio.h> > > __int64 x=0,y=0; > > __int64 extended_gcd(__int64 a,__int64 b) > { > __int64 t,v; > if(b==0) { > v=a; > x=1; > y=0; > } > else { > v=extended_gcd(b,a%b); > t=x; > x=y; > y=t-(a/b)*y; > } > return v; > } > > __int64 modular(__int64 a,__int64 b,__int64 n) > { > __int64 d,e; > d=extended_gcd(a,n); > if(b%d!=0) return -1; > e=x*(b/d)%n; > return e; > } > > int main() > { > __int64 a,b,x1,y1,n; > scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&x1,&y1,&n); > > if(y1-x1>0) > a=modular(y1-x1,(a-b)>0?(a-b):(a-b+n),n); > else > a=modular(x1-y1,(b-a)>0?(b-a):(b-a+n),n); > > if(a!=-1){ > if(a>=0) > printf("%I64d\n",a); > else > printf("%I64d\n",a+n); > } > else printf("Impossible\n"); > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator