


0 <= ‘ARR’[k] <= k
‘ARR’[k] = ‘ARR’[m] mod k, for all pairs of k,m such that k divides m.
Given ‘N’ = 3,
'A' = {0, -1, -1}
Then the answer is 6 because following sequences are possible:[0, 0, 0], [0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 0, 1], [0, 0, 2].
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains a single integer, ‘N,’ where ‘N’ is the number of elements of the array.
The second line of each test case contains ‘N’ space-separated integers, denoting the array elements.
For each test case, You are supposed to return the total number of nice arrays that can be formed.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 3000
0 <= 'ARR[i]’ <= 10 ^ 6
Time Limit: 1 sec.
The idea is that by using the Chinese Remainder Theorem, we can uniquely find ‘ARR[k]’ for a nice reconstructed sequence. The Chinese remainder theorem states that if one knows the remainder of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime.
We know that if we have a nice sequence we can find a set ‘S’, as each nice sequence corresponds to some set ‘S’. Conversely, let correspond to ‘ARR’. Then, for each prime and for each ‘K’, we can find a maximal ‘B’ such that ‘K’ is divisible by ‘P’ ^ ‘B’, where ‘P’ denotes a prime number.
That implies
‘ARR[k]’ is equivalent to ‘ARR[P ^ B], which in turn is congruent to ‘ARR[‘P’ ^ ‘A’] mod ‘P ^ B’.
Where ‘P’ ^ ‘A’ denotes the highest value which is less than ‘ARR[k]’.
The steps are as follows: