Binary multiplication. . . . actually. .

The main purpose of binary multiplication is to solve the multiplication result far beyond the int range, but the result needs to have a remainder multiplication operation

LL multi(LL a,LL b,LL m)
{
    LL ans = 0;
    a %= m;
    while(b)
    {
        if(b & 1)
        {
            years = (years + a) % m;
            b--;
        }
        b >>= 1;
        a = (a + a) % m;
    }
    return ans;
}
View Code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325151363&siteId=291194637