扩欧板子题
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<climits>
#include<string>
#include<cstdlib>
#include<ctime>
#define MAX 1000000007
#define LL long long
using namespace std;
LL x,y,z;
LL egcd(LL a,LL b,LL &x,LL &y)
{
int tmp,r;
if(!b)
{
x=1;
y=0;
return a;
}
r=egcd(b,a%b,x,y);
tmp=x;
x=y;
y=tmp-(a/b)*y;
return r;
}
int main()
{
LL a,b;
scanf("%lld%lld",&a,&b);
z=egcd(a,b,x,y);
LL t=b/z;
x=(x%t+t)%t;
printf("%lld",x);
return 0;
}