You are given an array 'NUM' consisting of N positive Integers. Your task is to find the total number of possible sequences of positive integers (greater than 1) whose product is 'X'.
The value of 'X' is calculated as the product of the N terms, where the ith term is generated by raising the ith prime number to the power of an ith element in the given array.
In mathematical terms, we can write X as:
X = 2 ^ NUM[1] * 3 ^ NUM[2] * 5 ^ NUM[3] * 7 ^ NUM[4] * 11 ^ NUM[5] * … up to Nth term
Note :
1. Sum of all the elements in the array 'NUM' will always be less than or equal to 400.
2. As the total number of such sequences can be very large, print the answer modulo 1000000007.
The first line of input contains a single integer T, representing the number of test cases
Then the T test cases follow.
The first line of each test case contains a number N denoting the size of the array 'NUM'.
The second line contains N space-separated integers, the elements of 'NUM'.
Output format:
For each test case print in a new line, an integer representing the total number of possible sequences of positive integers (greater than 1) whose product is X.
Note
You don’t have to print anything, it has already been taken care of. Just implement the given function.
1<= T <=10
2 <= N <= 500
1 <= NUM[i] < 100
Time Limit : 1 sec
1
3
1 0 1
3
For NUM = [1, 0, 1] : X = 2^1*3^0*5^1 which is equal to 10.
So all the possible sequences are {2, 5}, {5, 2}, {10}.
So the total number of sequences is 3.
2
2
0 2
2
0 3
2
4
(i) For 'NUM' = [0, 2] : X = 2^0*3^2 which is equal to 9.
So all the possible sequences are {3, 3}, {9}.
So the total number of sequences is 2.
(ii) For 'NUM' = [0, 3] : X = 2^0*3^3 which is equal to 27.
So all the possible sequences are {3, 9}, {9, 3}, {3, 3, 3}, {27}.
So the total number of sequences is 4.
Can you solve this problem using some combinatorics approach?
The idea is to make use of a combinatorics approach to find the contribution made by each element of the array in a total number of sequences.
Let’s understand with an example:
O(N * S), where N is the size of ‘NUM’ array/list and ‘S’ is the sum of all the elements of the given array.
As we are running two nested loops where the outer loop runs for ‘S’ times and the inner loop runs for ‘N’ times.
O(S), where ‘S’ is the sum of all the elements of the ‘NUM’ array.
We are using ‘ANS’ array/list of size ‘S’ and ‘BCOFF’ array of constant size. Hence, the overall space complexity is O(S).