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
Input
variables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2Output
[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
Input
variables = [[39,3,1000,1000]], target = 17Output
[]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