Steward
分享是一種喜悅、更是一種幸福
程式語言 - LeetCode - CPP - 372. Super Pow
參考資訊:
https://algo.monster/liteproblems/372
https://www.cnblogs.com/grandyang/p/5651982.html
https://www.cnblogs.com/grandyang/p/4383775.html
題目:

解答:
class Solution {
public:
int superPow(int a, vector<int>& b) {
using ll = long long;
const int MOD = 1337;
auto pow = [](ll base, int e) {
ll ans = 1;
while (e > 0) {
if (e & 1) {
ans = (ans * base) % MOD;
}
base = base * base % MOD;
e >>= 1;
}
return ans;
};
ll ans = 1;
for (int i = b.size() -1; i >= 0; --i) {
ans = (ans * pow(a, b[i])) % MOD;
a = pow(a, 10);
}
return ans;
}
};