poj 1061(扩展欧几里得算法)

#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
void gcd(ll a,ll b,ll&d,ll&x,ll&y){
    if(!b){
        d = a;x = 1;y = 0;
    }
    else{
        gcd(b,a%b,d,y,x);y -= x*(a/b);
    }
}
int main(){
    ll a,b,d,x,y,m,n,L,p,q,c,ans;
    scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&L);
    gcd(n-m,L,d,p,q);
    c = x-y;
    if(c%d!=0)printf("Impossible\n");
    else{
        ans = p*(c/d);
        ans = (ans%L+L)%L;
        printf("%lld\n",ans);
    }
    return 0;
}

 

posted @ 2021-07-28 21:31  智人心  阅读(33)  评论(0)    收藏  举报