Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
Input: a = 2, b = [3] Output: 8
Input: a = 2, b = [1,0] Output: 1024
impl Solution {
pub fn super_pow(a: i32, b: Vec<i32>) -> i32 {
let a = a % 1337;
let mut b = b;
let mut ret = 1;
let tmp = match b.pop() {
Some(n) => {
for _ in 0..n {
ret *= a;
ret %= 1337;
}
Self::super_pow(a, b)
},
None => 1,
};
for _ in 0..10 {
ret *= tmp;
ret %= 1337;
}
ret
}
}