题目链接:http://poj.org/problem?id=1061
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<climits>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<map>
using namespace std;
long long t, p, c;
void ou(int a, int b)
{
if(b == 0)
{
t = 1;
p = 0;
c = a;
}
else
{
ou(b, a%b);
int temp = t;
t = p;
p = temp - a/b*p;
}
}
int main()
{
int i, j, flag = 0, d, a, b;
long long x, y, m, n, l;
scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l);
if(n == m)
flag= 1;
else
{
a = n-m;
d = x-y;
b = l;
ou(a, b);
if(d % c !=0)
flag= 1;
}
if(flag)
printf("Impossible\n");
else
{
b = b / c;
d = d / c;
long long v = d * t;
printf("%d\n",(v%b+b)%b);
}
return 0;
}