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<iostream> using namespace std; long long Gcd(long long a,long long b,long long &x,long long &y){ if(!b){ x=1; y=0; return a;} long long x0,y0,c; c=Gcd(b,a%b,x0,y0); x=y0; y=x0-a/b*y0; return c; } int main(){ long long x,y,m,n,l; while(cin>>x>>y>>m>>n>>l){ long long w=x-y; w%=l; if(w*(m-n)>0){ if(w<0)w=-w; w=l-w;} if(w<0) w=-w; long long w2=m-n; if(w2<0)w2=-w2; long long q1,c,q2; c=Gcd(w2,l,q1,q2); if(q1<0)q1+=l; if(q1>l)q1-=l; if(w%c){ cout<<"Impossible\n"; continue;} q1*=w/c; q1%=l; while(q1<0)q1+=l; while(q1>l)q1-=l; cout<<q1<<"\n";} } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator