Modular exponentiation
Compute (base ** exp) % mod for non-negative integers base, exp, and a positive integer mod. The exponent exp can be as large as 10^9, so you cannot multiply exp times in a loop, and base**exp itself is far too large to materialize. Return the result as an integer in [0, mod). Note that when mod == 1 the answer is always 0.
Implement
fast_pow_mod(base: int, exp: int, mod: int) → intExamples
in
[2,10,1000]out24What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 18 min
solution.py
InputExpectedGot
[2,10,1000]24not run yetsample