MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / modularExponential

Function modularExponential

maths/modular_exponential.py:1–12  ·  view source on GitHub ↗
(base, power, mod)

Source from the content-addressed store, hash-verified

1def modularExponential(base, power, mod):
2 if power < 0:
3 return -1
4 base %= mod
5 result = 1
6
7 while power > 0:
8 if power & 1:
9 result = (result * base) % mod
10 power = power >> 1
11 base = (base * base) % mod
12 return result
13
14
15def main():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected