//VC 6.0不支持long long类型,这个需要留意
#include
#include
#include
using namespace std;
long long tx, py, c;
void extend_euild(int a, int b)
{
if(b == 0)
{
tx = 1;
py = 0;
c = a;
}
else
{
extend_euild(b, a%b);
int temp = tx;
tx = py;
py = temp - a/b*py;
}
}
int main()
{
int ok = 0, d, a, b;
long long x, y, m, n, l;
cin >> x >> y >> m >> n >> l;
x%=l;
y%=l;
if(n == m)
ok = 1;
else{
a = n-m;
d = x-y;
b = l;
extend_euild(a, b);
if(d % c !=0)
ok = 1;
}
if(ok)
cout << "Impossible" << endl;
else
{
b = b / c;
d = d / c;
long long v = d * tx;
cout << (v%b+b)%b << endl;
}
return 0;
}
阅读(621) | 评论(0) | 转发(0) |