372. Super Pow

problem

solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public:
int mod = 1337;
int myPow(int a, int k){
a = a%mod;
int ret =1;
for(int i=0;i<k ; ++i) ret = (ret*a) %mod;
return ret;
}
int superPow(int a, vector<int>& b) {
if(b.empty()) return 1;
int x = b.back();
b.pop_back();
int part1 = myPow(a,x);
int part2 = myPow(superPow(a,b),10);
return part1 *part2%mod;

}
};