| ||||||||||
| 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;
void Euclid(long long a,long long b,long long &x0,long long &y0);
long long gcd(long long a,long long b);
int main()
{
long long x,y,m,n,l;
cin>>x>>y>>m>>n>>l;
long long a,b,c;
if(m==n)goto eixt;
if(x>=l)x%=l;
if(y>=l)y%=l;
if(m>n){a=m-n;c=y-x;}
else {a=n-m;c=x-y;}
b=l;
long long p;
p=gcd(a,b);
if(c%p!=0)goto eixt;
if(p!=1)
{a/=p;b/=p;c/=p;}
Euclid(a,b,x,y);
x*=c;
while(x<=0)x+=b;
cout<<x;goto over;
eixt:
cout<<"Impossible";
over:
return 0;
}
long long gcd(long long a,long long b)
{
if(b==0)return a;
gcd(b,a%b);
}
void Euclid(long long a,long long b,long long &x0,long long &y0)
{
long long t;
if (b==0)
{
x0=1;y0=0;
return ;
}
Euclid(b,a%b,x0,y0);
t=x0;
x0=y0;
y0=t-(a/b)*y0;
return ;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator