POJ 1061

640阅读 0评论2010-03-12 renqingwei123
分类:

//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;
}
上一篇:POJ 1014
下一篇:POJ 2407