372. Super Pow - cocoder39/coco39_LC GitHub Wiki
class Solution {
public:
int superPow(int a, vector<int>& b) {
if (b.empty()) {
return 1;
}
const int base = 1337;
int last_digit = b.back();
b.pop_back();
return powmod(superPow(a, b), 10, base) * powmod(a, last_digit, base) % base;
}
private:
int powmod(int a, int k, const int base) {
a %= base;
int res = 1;
for (int i = 0; i < k; i++) {
res = (res * a) % base;
}
return res;
}
};