拓展欧几里得

 

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

void exgcd(int a,int b,LL &x,LL &y){
    if(b==0){x=1, y=0; return;}
    LL tx,ty;
    exgcd(b,a%b,tx,ty);
    x=ty;
    y=tx-(a/b)*ty;
}

int main(){
    LL a,b,x,y;
    cin>>a>>b;
    exgcd(a,b,x,y);
    x=(x%b+b)%b;
    cout<<x<<endl;
    return 0;
}

posted @ 2017-07-20 19:50  wqtnb_tql_qwq_%%%  阅读(179)  评论(0编辑  收藏  举报