【题目分析】
拓展欧几里得
【代码】
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#define L long long
using namespace std;
L x,y,m,n,l,d,p,q;
inline void exgcd(L a,L b,L&d,L &x,L &y)//拓展的欧几里得 ,顺便计算最大公约数
{
if (b==0) {x=1;y=0;d=a;return;}
exgcd(b,a%b,d,y,x);
y-=x*(a/b);
}
int main()
{
scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l);//猥琐的读入
exgcd(m-n,l,d,p,q);
if ((y-x)%d)
{
printf("Impossible\n");
return 0;
}
L tmp=abs(l/d);
printf("%lld\n",((p*(y-x)/d)%tmp+tmp)%tmp);
}