POJ 1061 青蛙的约会(拓展欧几里得)

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#define LL long long
using namespace std;
LL egcd(LL a,LL b,LL &x,LL &y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    LL r=egcd(b,a%b,x,y);
    LL t=x;
    x=y;
    y=t-a/b*y;
    return r;
}
int main()
{
    LL x,y,n,m,l;
    scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l);
    LL a=n-m;
    LL b=l;
    LL c=x-y;
    if(a<0)
    {
        a=-a;
        c=-c;
    }
    LL gcd=egcd(a,b,x,y);
    if(c%gcd)
        printf("Impossible
");
    else
    {
        x=x*(c/gcd);
        LL x0=(x%(b/gcd)+b/gcd)%(b/gcd);
        printf("%lld
",x0);
    }
}
原文地址:https://www.cnblogs.com/nr1999/p/9406866.html