贴代码:
ll exgcd(ll a,ll b,ll &x,ll &y){
if(b==0){
x=1,y=0;
return a;
}
else{
ll gcd=exgcd(b,a%b,y,x);
y-=(a/b)*x;
return gcd;
}
}
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif // LOCAL
ll x,y,m,n,l,s,t;
while(cin>>x>>y>>m>>n>>l){
ll a,b;
if(m==n){
puts("Impossible");
continue;
}
a=m-n,b=y-x;
ll gcd=exgcd(a,l,t,s);
if(b%gcd==0){
ll d=b/gcd;
a/=gcd,l/=gcd;
exgcd(a,l,t,s);
l*=gcd;
t=((t*d)%l+l)%l;
}
else{
puts("Impossible");
continue;
}
cout<<t<<endl;
}
return 0;
}