【BZOJ1477】青蛙的约会

problem

solution

codes

#include<iostream>
using namespace std;
typedef long long LL;
LL exgcd(LL a, LL b, LL &x, LL &y){
    if(!b){
        x = 1, y = 0;
        return a;
    }
    LL r = exgcd(b, a%b, x, y);
    LL t = x;
    x = y;
    y = t-a/b*y;
    return r;
}
int main(){
    LL x, y, m, n, L, X, Y;
    cin>>x>>y>>m>>n>>L;
    LL a = n-m, d = x-y;
    if(a < 0){ a = -a;  d = -d; }// it be must
    LL c = exgcd(a, L, X, Y);
    if(d%c != 0)cout<<"Impossible\n";
    else cout<<(X*(d/c)%(L/c)+(L/c))%(L/c)<<"\n";//WA%->#5 ->#10(L/c)==c
    return 0;
}
posted @ 2018-05-25 13:18  gwj1139177410  阅读(79)  评论(0编辑  收藏  举报
选择