题目来源
一道数学题…
主要用到了ab % k = (a%k)(b%k)%k
代码如下:
class Solution {
const int base = 1337;
int powMod(int a, int b)
{
a %= base;
int res = 1;
for (int i=0; i<b; i++)
res = res * a % base;
return res;
}
public:
int superPow(int a, vector<int>& b) {
if (b.size() == 0)
return 1;
int last_digit = b.back();
b.pop_back();
return powMod(superPow(a, b), 10) * powMod(a, last_digit) % base;
}
};