这是一个中文题,两只青蛙在相同的纬度向相同的方向跳,问何时才能相遇。
#include<stdio.h>
long long gcd(long long a,long long b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
void exgcd(long long a,long long b,long long& x,long long& y)
{
if(b==0)
{
x=1;
y=0;
return ;
}
else
{
exgcd(b,a%b,y,x);
y-=x*(a/b);
}
}
int main()
{
long long x,y,m,n,l,a,b,c,r,t,k1,k2;
while(scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l)!=EOF)
{
a=n-m;
b=l;
c=x-y;
r=gcd(a,b);
if(c%r||m==n)
{
printf("Impossible\n");
}
else
{
a=a/r;
b=b/r;
c=c/r;
exgcd(a,b,k1,k2);
t=k1*c/b;
t=c*k1-b*t;
if(t<0)
t+=b;
printf("%lld\n",t);
}
}
return 0;
}