super-pow

// 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;
        
    }
};

 

posted @ 2016-07-10 14:10  blcblc  阅读(186)  评论(0编辑  收藏  举报