题解可参考:https://www.luogu.com.cn/blog/cicos/solution-p1082#
#include <bits/stdc++.h> # define LL long long using namespace std; LL a,b; LL x,y; void exgcd(LL a, LL b){ if(b==0){ x=1; y=0; return; } exgcd(b,a%b); LL tmp=x; x=y; y=tmp-a/b*y; } int main(){ scanf("%lld %lld", &a, &b); exgcd(a,b); x=(x%b+b)%b; printf("%lld", x); return 0; }