求n关于mod的逆元
#include <stdio.h>
#define LL long long
void ext_gcd(int a,int b, int &x, int &y){
if(!b)x=1, y=0;
else {
ext_gcd(b, a%b, y, x);
y-=(a/b)*x;
}
}
int main(){
int n, mod;
scanf("%d%d", &n, &mod);
int x, y;
ext_gcd(n, mod, x, y);
printf("%d\n", ((x%mod+mod)%mod));
return 0;
}