Leetcode 372 Solution

This article provides solution to leetcode question 372 (super-pow)

https://leetcode.com/problems/super-pow

Solution

class Solution {
public:
    int pow(int a, int b)
    {
        if (b == 0)
            return 1;

        int64_t c = pow(a, b / 2);

        if (b % 2 == 0)
            return (c * c) % 1337;
        else
            return (c * c * a) % 1337;
    }

    int superPow(int a, vector<int>& b) {
        int c = 1;

        for (int i = 0; i < b.size(); i++)
            c = (pow(c, 10) * pow(a, b[i])) % 1337;

        return c;
    }
};