#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;
}
时间: 2024-10-27 13:22:12