// https://discuss.leetcode.com/topic/50489/c-clean-and-short-solution class Solution { int base = 1337; int powMod(int a, int b) { a %= base; int result = 1; for (int i=0; i<b; i++) { result *= a; result %= base; } return result; } public: int superPow(int a, vector<int>& b) { if (b.empty()) { return 1; } int t = b.back(); b.pop_back(); return (powMod(superPow(a, b), 10) * powMod(a, t)) % base; } };