https://leetcode-cn.com/problems/super-pow/submissions/
class Solution {
int mod = 1337;
public int superPow(int a, int[] b) {
return dfs(a,b,b.length-1);
}
private int dfs(int a,int[] b,int len){
if(len == -1) return 1;
int pre = pow(dfs(a,b,len-1),10) ;
int aft = pow(a,b[len]);
return pre * aft % mod ;
}
/**
*
* @param m
* @param n
* @return m^n % mod
*/
private int pow(int m,int n){
int tmp = 1;
// (a * b) mod c = [ (a mod c) * (b mod c)] mod c
m %= mod;
while(n-- > 0){
tmp = tmp * m % mod;
}
return tmp;
}
}