#include<cstdio>
#include<cstring>
#define LL long long
LL exgcd( LL a,LL b,LL &x,LL &y)
{
int d=a;
if(b!=0)
{
d=exgcd(b,a%b,y,x);
y-=(a/b)*x;
}
else
{
x=1;
y=0;
}
return d;
}
int main()
{
LL a,b,c,d,x,y,l,t;
scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&l);
LL gcd=exgcd(c-d,l,x,y);
if((b-a)%gcd==0)
{
x*=(b-a)/gcd;
t=l/gcd;
if(t<0)
t=-t;
x=(x%t+t)%t;
printf("%lld\n",x);
}
else
printf("Impossible\n");
return 0;
}
poj 1061 扩展欧几里德
最新推荐文章于 2019-08-01 11:45:13 发布