OrderedProduct
SRM 711 · 2017-02-20 · by Arterm
Problem Statement
Let p[] be an infinite array containing all prime numbers in ascending order. That is, p[0]=2, p[1]=3, p[2]=5, p[3]=7, and so on.
You are given a
Compute the number of sequences of positive integers such that each integer is greater than 1 and the product of all elements of the sequence is exactly X. Return that number modulo 1,000,000,007.
Constraints
- a will contain between 1 and 50 elements, inclusive.
- Each element of a will be between 1 and 50, inclusive.
{1, 1}
Returns: 3
Here, X = 2^1 * 3^1 = 6. There are three valid sequences: (2,3), (3,2), and (6).
{2}
Returns: 2
We have X = 2^2 = 4. The two valid sequences are (2,2) and (4).
{1, 1, 1, 1, 1}
Returns: 541
{23, 49, 12}
Returns: 316396073
Watch out for integer overflow.
{2, 5, 4, 2, 3, 1, 3, 1, 4, 6}
Returns: 225466557
Submissions are judged against all 28 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class OrderedProduct with a public method int count(vector<int> a) · 28 test cases · 2 s / 256 MB per case