乘法逆元

#include
#define ll long long
ll exgcd(ll a,ll b,ll &x,ll &y){
	if(b==0){
		x=1;
		y=0;
		return a;
	}
	ll gcd=exgcd(b,a%b,y,x);
	y-=(a/b)*x;
	return gcd;
}
ll inv(ll a,ll p){
	ll x,y;
	return exgcd(a,p,x,y)==1?(x+p)%p:-1;
}
int main(){
	ll a,p;
	std::cin>>a>>p;
	std::cout<

 

你可能感兴趣的:(我的算法小笔记)