求解逆元的两种方法

int exgcd(ll a, ll b, ll &x, ll &y) {
	if(b == 0) {
		x = 1; y = 0;
		return a;
	}
	ll gcd = exgcd(b, a % b, x, y);
	ll tmp= x;
	x = y;
	y = tmp - (a / b) * y;
	return gcd;
}
ll quick(ll x, ll p) {
	ll res = 1;
	ll d = p - 2;
	while(d) {
		if(d & 1)	res = res*x%p;
		x = x*x%p;
		d >>= 1;
	}
	return res;
}

你可能感兴趣的:(求解逆元的两种方法)