您的位置:首页 > 其它

super-pow

2016-07-10 14:10 417 查看
// 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;

}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: