1631:【例 1】青蛙的约会

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll x,y,L,m,n;
void Exgcd(ll a,ll b,ll &d,ll &x,ll &y)
{
    if(!b) 
    {
        x=1;y=0;d=a;
    }
    else
    {
        Exgcd(b,a%b,d,x,y);
        int t=x;x=y;y=t-a/b*y;
    }
}
int main()
{
    ll a,b,d;
    scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&L);
    if(n<m) swap(n,m),swap(x,y);
    Exgcd(n-m,L,d,a,b);
    if((x-y)%d!=0||m==n) printf("Impossible\n");
     else printf("%lld\n",(a*(x-y)/d%(L/d)+(L/d))%(L/d));
    return 0;
}

 

posted @ 2019-08-24 16:34  Gold_stein  阅读(260)  评论(0编辑  收藏  举报