| ||||||||||
| 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 | |||||||||
测试大量数据都可以,为何wa?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator