Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:你只有一个CASE...

Posted by lxp_rs at 2006-08-21 23:13:04 on Problem 1061
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator