Super Pow

作者: 我叫胆小我喜欢小心 | 来源:发表于2017-05-05 10:43 被阅读12次

    题目来源
    一道数学题…
    主要用到了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;
        }
    };
    

    相关文章

      网友评论

          本文标题:Super Pow

          本文链接:https://www.haomeiwen.com/subject/smmjtxtx.html