2961. 双模幂运算
题目链接:2961. 双模幂运算
代码如下:
class Solution
{
public:
vector<int> getGoodIndices(vector<vector<int>>& variables, int target)
{
vector<int> res;
for (int i = 0; i < variables.size(); i++)
{
auto& v = variables[i];
if (pow_mod(pow_mod(v[0], v[1], 10), v[2], v[3]) == target)
{
res.push_back(i);
}
}
return res;
}
private:
int pow_mod(int x, int y, int mod)
{
int res = 1;
while (y)
{
if (y & 1)//判断最后一位是否是1
{
res = res * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return res;
}
};