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

测试大量数据都可以,为何wa?

Posted by shanjiaoxiaread at 2012-03-29 18:54:32 on Problem 1061
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
 long long  exGcd( long  long a, long long b,long long* x,long long * y){
    long long r,t;
	if(b==0){
	  *x=1;
	  *y=0;
	  return a;
	}
    r=exGcd(b,a%b,x,y);
    t=*x;
	*x=*y;
	*y=t-a/b*(*y);
    return r;
}
int main(int argc,char ** argv){
	long long  x,y,m,n,l,cirNum,gcd,M,time,a,b,c,temp;
      while(scanf("%lld %lld %lld %lld %lld",&x,&y,&m,&n,&l)==5){
	     if(((x%l)==(y%l))||x>=2000000000||y>=2000000000||m>=2000000000||
						m<=0||n>=2000000000||n<=0||l>=2100000000||l<=0){
                 continue;     
		}
      if(n<m){
          temp=n;
	    n=m;
          m=temp;
          temp=x;
          x=y;
          y=temp;

	 }
    M =exGcd(l,n-m,&cirNum,&time);
    if((x-y)%M!=0)
		printf("Impossible\n");
	else{
         
	  b=l/M;
	  c=(x-y)/M;
	  a=(n-m)/M;
        exGcd(b,abs(a),&cirNum,&time);
	  time*=c;
	  while(time<0)
		  time+=b;
        if(time>b)
              time=time%b;

		printf("%lld\n",time);
	}
	}
	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