poj1061 青蛙的约会

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
__int64 x,y;
__int64 extended_gcd(__int64 a,__int64 b)
{
    __int64 t,gcd;
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    gcd=extended_gcd(b,a%b);
    t=x;
    x=y;
    y=t-a/b*y;
    return gcd;
}
int main()
{
    __int64 p,q,m,n,l;
    scanf("%I64d %I64d %I64d %I64d %I64d",&p,&q,&m,&n,&l);
    __int64 a,b,c;
    a=m-n;
    b=l;
    c=q-p;
    __int64 d=extended_gcd(a,b);
    if(c%d!=0)
    {
        printf("Impossible\n");
        return 0;
    }
    x=x*c/d;
    x=x%b;
    while(x<0)
    {
        x+=b;
    }
    //x=(b/d+x%(b/d))%(b/d);
    printf("%I64d\n",x);
    return 0;
}

posted @ 2012-07-12 08:44  willzhang  阅读(102)  评论(0编辑  收藏  举报