Math/Exponentiation by Squaring + Modular Inverse.cpp
// Iterative solution (less memory used)
Iterative solution (less memory used)
Iterative solution ( less memory used )
lld fastpow_it(lld a, lld b)
{
    lld ret = 1;
    while(b > 0)
    {
        if(b & 1)
            ret *= a;
        b >>= 1;
        a *= a;
    }
    return ret;
}
lld fastpow_it ( lld a , lld b ) { lld ret = 1 ; while ( b > 0 ) { if ( b & 1 ) ret *= a ; b >>= 1 ; a *= a ; } return ret ; }
Iterative solution (less memory used)
Iterative solution ( less memory used )
// a^b = a^(2^b1 + 2^b2 + ... 2^bn) [ bi - ith bit position ] //     = a^(2^b1) * a^(2^b2) * ... * a^(2^bn)