Answers for "Modulo Exponentiaon,Iteratve Modulo Exponentiation,Binary Exponentiation"

0

Modulo Exponentiaon,Iteratve Modulo Exponentiation,Binary Exponentiation

long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
Posted by: Guest on June-17-2021
0

Modulo Exponentiaon,Iteratve Modulo Exponentiation,Binary Exponentiation

long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
Posted by: Guest on May-13-2021

Browse Popular Code Answers by Language