(a: int, n: float, mod: int)
| 6 | |
| 7 | |
| 8 | def binary_exponentiation(a: int, n: float, mod: int) -> int: |
| 9 | if n == 0: |
| 10 | return 1 |
| 11 | |
| 12 | elif n % 2 == 1: |
| 13 | return (binary_exponentiation(a, n - 1, mod) * a) % mod |
| 14 | |
| 15 | else: |
| 16 | b = binary_exponentiation(a, n / 2, mod) |
| 17 | return (b * b) % mod |
| 18 | |
| 19 | |
| 20 | # a prime number |
no outgoing calls
no test coverage detected