typedef long long ll;
const ll mod = 1000000007;
ll q_mul(ll a,ll b,ll mod) // 快速乘
{
ll res = 0;
ll tmp = b;
ll tmp1 = a;
while(tmp)
{
if(tmp&1) res = ((res%mod) + (tmp1%mod))%mod;
tmp1 = (tmp1<<1)%mod;
tmp >>= 1;
}
return res%mod;
}
ll q_pow(ll a,ll b,ll mod) // 快速幂
{
ll res = 1;
ll tmp = b;
ll tmp1 = a;
while(tmp)
{
if(tmp&1) res = q_mul(res,tmp1,mod);
tmp1 = (tmp1*tmp1)%mod;
tmp >>= 1;
}
return res%mod;
}
快速幂+快速乘模板
最新推荐文章于 2022-12-10 15:35:42 发布