75. Fast Exponentiation (Modular Power)
MediumDivide & conquer
Return (base ^ exp) mod m using O(log exp) multiplications. All inputs are non-negative and m ≥ 1.
Example 1
Input: base = 2, exp = 10, m = 1000 Output: 24 Explanation: 1024 mod 1000
Constraints
0 ≤ base, exp ≤ 10⁹1 ≤ m ≤ 46340 (so products stay exact)