Modular exponentiation large exponent

Write codeMedium25 min

Your task

Compute a^b mod m using fast (binary) exponentiation, where b is given as a list of decimal digits of a potentially very large exponent (most-significant digit first). Return (a^b) mod m. Constraints: 0 <= a < 10^9, m >= 1, and the digit list has length 1..50 with each entry in 0..9 (no leading-zero requirement; the list [0] means exponent 0).

Examples

pow_big_exp(a: int, digits: list[int], m: int) -> int
Example 1
Inputpow_big_exp(2, [1, 0], 1000)
Output24