快速幂优化

typedef long long ll;
ll quick_mul(ll a, ll b, ll m) {//快速乘法运算 
	ll ans = 0;
	while(b) {
		if(b&1) 
		ans = (ans + a) % m;
		a = (a + a) % m;
		b>>=1;
	}
	return ans;
}
ll quick_pow(ll a, ll b, ll m) {//快速幂运算 
	ll ans = 1;
	while(b) {
		if(b&1)
		ans = quick_mul(ans , a , m);
		a = quick_mul(a , a , m);
		b>>=1;
	}
	return ans;
}

你可能感兴趣的:(数论)