间接的快速幂——372. 超级次方

题目


OJ平台

手写题解

解题代码

class Solution {
    
    
    const int MOD = 1337;

    int pow(int x, int n) {
    
    
        int res = 1;
        while (n) {
    
    
            if (n % 2) {
    
    
                res = (long) res * x % MOD;
            }
            x = (long) x * x % MOD;
            n /= 2;
        }
        return res;
    }

public:
    /**/ 
    int superPow(int a, vector<int> &b) {
    
    
        int ans = 1;
        for (int i = b.size() - 1; i >= 0; --i) {
    
    
            ans = (long) ans * pow(a, b[i]) % MOD;
            a = pow(a, 10);
        }
        return ans;
    }
};

猜你喜欢

转载自blog.csdn.net/m0_50945504/article/details/121733333
今日推荐