HDU 4390 组合数学&数论

本文深入探讨了数列乘积问题的求解策略,通过分解素因子和利用组合数学原理,揭示了如何计算满足特定乘积条件的序列数量。通过实例演示,展示了从数列分解到组合分配的过程,最终输出符合要求的序列数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

传送门: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).
 

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

将所有的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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值