Count sequences of positive integers having product X
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.
Input Format:
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.
Constraints
1<= T <=10
2 <= N <= 500
1 <= NUM[i] < 100
Time Limit : 1 sec
CodingNinjas
author
2y
Combinatorics
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.
- The maximum number of positive integers in a...read more
Help your peers!
Add answer anonymously...
Top TCS iON Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app