您的位置:首页 > 产品设计 > UI/UE

leetcode:数学:spuer pow(372)

2016-08-31 14:24 344 查看
https://leetcode.com/problems/super-pow/

http://blog.csdn.net/happyxuma1991/article/details/51867822

class Solution {
const int base = 1337;
int powmod(int a, int k) //a^k mod 1337 where 0 <= k <= 10
{
a %= base;
int result = 1;
for (int i = 0; i < k; ++i)
result = (result * a) % base;
return result;
}
public:
int superPow(int a, vector<int>& b) {
if (b.empty()) return 1;
int last_digit = b.back();
b.pop_back();
return powmod(superPow(a, b), 10) * powmod(a, last_digit) % base;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: