# LeetCode - 2961. Double Modular Exponentiation ### 題目網址:https://leetcode.com/problems/double-modular-exponentiation/ ###### tags: `LeetCode` `Medium` `模擬` `快速冪` ```cpp= /* -LeetCode format- Problem: 2961. Double Modular Exponentiation Difficulty: Medium by Inversionpeter */ int FastPower(int base, int power, int mod) { int answer = 1, buffer = base; while (power) { if (power & 1) { answer = ((long long)answer * buffer) % mod; } buffer = ((long long)buffer * buffer) % mod; power >>= 1; } return answer; } class Solution { public: vector<int> getGoodIndices(vector<vector<int>>& variables, int target) { vector <int> goodies; for (int i = 0; i != variables.size(); ++i) { if (FastPower(FastPower(variables[i][0], variables[i][1], 10), variables[i][2], variables[i][3]) == target) { goodies.push_back(i); } } return goodies; } }; ```