#include <stdio.h>
int gcd(int a,int b)
{
if(b!=0)
return gcd(b,a%b);
else
return a;
}
int main()
{
long long x,y,m,n,l;
long long road,speed;
while(scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l)!=-1)
{
speed=m<n?n-m:m-n;
if(m>n)
road=(l+y-x)%l;
else
road=(l+x-y)%l;
if(m==n||road%gcd(speed,l))
{
printf("Impossible\n");
continue;
}
long long i=0;
while(1)
{
if((l*i+road)%speed==0)
{
printf("%lld\n",(l*i+road)/speed);
break;
}
i++;
}
}
return 0;
}
POJ1061 - 青蛙的约会 - 数论
最新推荐文章于 2018-09-21 21:44:55 发布