C++


  • -1
    S

    class Solution {
    public:
    int euler(int x) {
    int ret = x;
    for(int i = 2; i * i <= x; ++i) {
    if(x % i == 0) {
    while(x % i == 0) x /= i;
    ret = ret * (i - 1) / i;
    }
    }
    if(x > 1) ret = ret * (x - 1) / x;
    return ret;
    }
    long long pow_mod(long long a, long long b) {
    long long ret = 1;
    while(b) {
    if(b&1) ret = (ret * a) % 1337;
    a = (a * a) % 1337;
    b >>= 1;
    }
    return ret;
    }
    int superPow(int a, vector<int>& b) {
    if(a == 1) return 1;
    int x = 0;
    int n = b.size();
    int mod = euler(1337);
    for(int i = 0; i < n; ++i) {
    x = (x * 10 + b[i]) % mod;
    }
    return pow_mod(a, x + mod);
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.