LandscapeMi

landscapemi的博客

leetcode:数学:spuer pow(372)

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;  
    }  
};  
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mijian1207mijian/article/details/52384689
个人分类: leetcode(c++)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

leetcode:数学:spuer pow(372)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭