Double Modular Exponentiation

You are given a 0-indexed 2D array variables where variables[i] = [ai, bi, ci, mi], and an integer target.

An index i is good if both of the following hold:

  • 0 <= i < variables.length
  • ((ai^bi % 10)^ci) % mi == target

Return an array consisting of good indices in any order.

Example 1
Inputvariables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2
Output[0,2]
For indices 0 and 2, the formula evaluates to 2, while for index 1 it evaluates to 0, so the good indices are [0, 2].
Example 2
Inputvariables = [[39,3,1000,1000]], target = 17
Output[]
For the only index, the formula evaluates to 1, so there are no good indices.

Constraints

  • 1 <= variables.length <= 100
  • variables[i] == [ai, bi, ci, mi]
  • 1 <= ai, bi, ci, mi <= 10^3
  • 0 <= target <= 10^3

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate