POJ - 1061 青蛙的约会

#include <cstdio>
using namespace std;
#define LL __int64

LL x0, y0;

int gcd(LL a, LL b)
{
    LL flag, r;
    if(b==0){
        x0 = 1;
        y0 = 0;
        return a;
    }
    r = gcd(b, a%b);
    flag = x0;
    x0 = y0;
    y0 = flag-a/b*y0;

    return r;
}

int main()
{
    LL x, y, m, n, l;
    LL a, b, c, r, x1, xx;
    LL t;

    while( scanf("%I64d%I64d%I64d%I64d%I64d", &x, &y, &m, &n, &l) !=-1){
        a = m-n;
        b = -l;
        c = y-x;
        r=gcd(a, b);

        if( c%r!=0 )
            printf("Impossible\n");
        else{
            x1 = c/r * x0;
           // y1 = c/r * y0;
            t = x1/(b/r);
            xx = x1- ((b/r) *t);
            if(xx < 0)  xx = xx+b/r;
            printf("%I64d\n", xx);
        }
    }

    return 0;
}

你可能感兴趣的:(POJ - 1061 青蛙的约会)