传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4390
Number Sequence
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1067 Accepted Submission(s): 428
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).
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).
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
4HintFor 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
将所有的b[i]进行素因子分解,则a和b的因子是完全一致的。
剩下的便是将所有b的因子,分给a
我们考虑某个素因子pi,如果有ci个,便成了子问题将ci个相同的物品放入到n个不同的容器中,种数为多少
但是要求ai>1,也就是容器不能为空,这是个问题。
我们考虑的是什么的情况,然后减去假设有一个确定是空的情况,发现可以用容斥原理解决
将m个物品放到到不同的n个容器中,结果为c(n+m-1,n-1)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define LL long long
#define MOD 1000000007
int n;
LL C[501][501];
LL cnt[1000001];
void init(){
C[0][0]=1;
for(int i=1;i<501;i++){
C[i][0]=C[i][i]=1;
for(int j=1;j<i;j++)
C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
}
}
void doit(int x){
for(int i=2;i*i<=x;i++){
while(x%i==0){
x/=i;
cnt[i]++;
}
}
if(x>1)cnt[x]++;
}
vector<LL>p;
void solve(){
p.clear();
for(int i=0;i<1000001;i++)
if(cnt[i])p.push_back(cnt[i]);
int len=p.size();
LL ans=1;
for(int i=0;i<len;i++)
ans=ans*C[p[i]+n-1][n-1]%MOD;
for(int i=1;i<n;i++){
LL tmp=C[n][i];
for(int j=0;j<len;j++)
tmp=tmp*C[p[j]+n-i-1][n-i-1]%MOD;
if(i&1)ans=((ans-tmp)%MOD+MOD)%MOD;
else ans=(ans+tmp)%MOD;
}
printf("%I64d\n",ans);
}
int main(){
init();
while(~scanf("%d",&n)){
memset(cnt,0,sizeof cnt);
for(int i=0;i<n;i++){
int x;scanf("%d",&x);
doit(x);
}
solve();
}
return 0;
}