Number Sequence
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Given a number sequence b 1,b 2…b n. Please count how many number sequences a 1,a 2,...,a n satisfy the condition that a 1*a 2*...*a n=b 1*b 2*…*b n (a i>1).
Input
The input consists of multiple test cases. For each test case, the first line contains an integer n(1<=n<=20). The second line contains n integers which indicate b 1, b 2,...,b n(1<b i<=1000000, b 1*b 2*…*b n<=10 25).
Output
For each test case, please print the answer module 1e9 + 7.
Sample Input
2 3 4
Sample Output
4
Hint
For the sample input, P=3*4=12. Here are the number sequences that satisfy the condition: 2 6
3 4
4 3
6 2
Source
将每一个数分解质因数,得到每个质因数出现的次数(和质数本身没有关系),然后就要用到容斥原理了,
也就是将每个质数出现的次数放到n个容器中去,这里要注意下1的情况也就是某个容器里面没有放数。
这样结果=总的方案数-有一个容器没放数+有2个容器没有放数……
将m个数放入n个容器的方法数有C(n+m-1,n-1) 。
#include#include #include #include #include #include #include #include #include #include