def modular_exponential(base, exponent, mod):
if exponent < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>base %= mod<EOL>result = <NUM_LIT:1><EOL>while exponent > <NUM_LIT:0>:<EOL><INDENT>if exponent & <NUM_LIT:1>:<EOL><INDENT>result = (result * base) % mod<EOL><DEDENT>exponent = exponent >> <NUM_LIT:1><EOL>base = (base * base) % mod<EOL><DEDENT>return result<EOL>
Computes (base ^ exponent) % mod.
    Time complexity - O(log n)
    Use similar to Python in-built function pow.