代码
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
ll ExGcd(ll a,ll b,ll& x,ll& y) {
if(b==0) {
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;
}
ll a,b,x,y;
int main(){
cin>>a>>b;
ExGcd(a,b,x,y);
cout<<(x+b)%b<<endl;
}