You are given an array of positive integers nums and a positive integer k. You are also given a 2D array queries, where queries[i] = [index_i, value_i, start_i, x_i].
You are allowed to perform an operation once on nums, where you can remove any suffix from nums such that nums remains non-empty.
The x-value of nums for a given x is defined as the number of ways to perform this operation so that the product of the remaining elements leaves a remainder of x modulo k.
For each query in queries you need to determine the x-value of nums for x_i after performing the following actions:
- Update
nums[index_i]tovalue_i. Only this step persists for the rest of the queries. - Remove the prefix
nums[0..(start_i - 1)](wherenums[0..(-1)]will be used to represent the empty prefix).
Return an array result of size queries.length where result[i] is the answer for the i-th query.
Note that the prefix and suffix to be chosen for the operation can be empty.
Input & Output
Constraints
- 1 ≤ nums.length ≤ 105
- 1 ≤ nums[i] ≤ 109
- 1 ≤ k ≤ 109
- 1 ≤ queries.length ≤ 105
- queries[i].length = 4