Medium

Double Modular ExponentiationPython

Full explanation · Time O(n * (logb + logc)) · Space O(1)

# Time:  O(n * (logb + logc))
# Space: O(1)

# fast exponentiation
class Solution(object):
    def getGoodIndices(self, variables, target):
        """
        :type variables: List[List[int]]
        :type target: int
        :rtype: List[int]
        """
        return [i for i, (a, b, c, m) in enumerate(variables) if pow(pow(a, b, 10), c, m) == target]