http://poj.org/problem?id=1061
题意:裸题。注意负数。
//poj1061
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std; typedef long long LL;
LL tx,ty; LL exgcd(LL a,LL b)
{
if(b==) {tx=,ty=;return a;}
LL d=exgcd(b,a%b);
LL x=ty,y=tx-(a/b)*ty;
tx=x;ty=y;
return d;
} int main()
{
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
LL x,y,m,n,l;
scanf("%I64d%I64d%I64d%I64d%I64d",&x,&y,&m,&n,&l);
LL g=exgcd(m-n,l);
// printf("g = %I64d\n",g);
if((y-x)%g!=) printf("Impossible\n");
else {
LL rx=tx*(y-x)/g;
LL r=l/g;
if(r<) r*=-;
rx=(rx%r+r)%r;
printf("%I64d\n",rx);
}
return ;
}