#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
LL e_gcd(LL a,LL b,LL &x,LL &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
LL ans=e_gcd(b,a%b,x,y);
LL temp=x;
x=y;
y=temp-a/b*y;
return ans;
}
int main()
{
LL x,y,m,n,l;
while(cin>>x>>y>>m>>n>>l)
{
LL a=n-m,b=l,c=x-y,r;
r=__gcd(a,b);
if(c%r)
{
cout<<"Impossible"<<endl;
continue;
}
a/=r;
b/=r;
c/=r;
e_gcd(a,b,x,y);
LL ans=c*x%b;
if(ans<0)
ans+=b;
cout<<ans<<endl;
}
return 0;
}
poj 1061 青蛙的约会
最新推荐文章于 2021-10-06 17:26:28 发布