讲解&代码
1.龟速乘
类似快速幂的思想,直接搞即可
LL gsc(LL x,LL y,LL MOD)//~~光~~龟速乘
{
LL ret = 0;
while(y){if(y & 1) ret = (ret + x) % MOD;x = (x << 1) % MOD;y >>= 1;}
return ret;
}
2.光速乘
LL gsc(LL x,LL y,LL MOD)
{
LL ret = x*y - (LL)((long double)x/MOD*y+0.5)*MOD;
return (ret%MOD+MOD)%MOD;
}