CF 396A On Number of Decompositions into Multipliers(组合数学)

You are given an integer m as a product of integers a1, a2, ...an . Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers.

Decomposition into n products, given in the input, must also be considered in the answer. As the answer can be very large, print it modulo1000000007 (109 + 7).

Input

The first line contains positive integer n (1 ≤ n ≤ 500). The second line contains space-separated integersa1, a2, ..., an (1 ≤ ai ≤ 109).

Output

In a single line print a single number k — the number of distinct decompositions of numberm into n ordered multipliers modulo1000000007 (109 + 7).

Examples
Input
1
15
Output
1
Input
3
1 1 2
Output
3
Input
2
5 7
Output
4
Note

In the second sample, the get a decomposition of number 2, you need any one number out of three to equal 2, and the rest to equal 1.

In the third sample, the possible ways of decomposing into ordered multipliers are [7,5], [5,7], [1,35], [35,1].

A decomposition of positive integer m inton ordered multipliers is a cortege of positive integersb = {b1, b2, ...bn} such that . Two decompositions b and c are considered different, if there exists index i such that bi ≠ ci.


题意:有n个数,把这n个数分为a1到an个数连乘。(比方说n为2,这两个数为3,5,则可以有1,35; 5,7; 7,5;35,1;)

分析:可以将这n个数全部分解为素因子,然后将每种素因子(设为k个)分别放到n个位置。用隔板法求得为每种总数为c(n+m-1,n-1)。

          


#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#define LL  long long
#define N 37000
const int  MOD=1e9+7;
using namespace std;
map<int,int> mp;
bool is[N+10];
LL prime[N],k,n;
LL jc[N+10],fjc[N+10];
void addm(int x)
{
    for(int i=1;prime[i]*prime[i]<=x;i++)
    {
        while(x%prime[i]==0)
        {
            mp[prime[i]]++;
           x/=prime[i];
        }
        if(x==1)break;
    }
    if(x>1)mp[x]++;
}
LL quickmi(LL x,LL m)   //快速幂
{
    LL ans=1;
    while(m>0)
    {
        if(m&1)
            ans=(ans*x)%MOD;
        x=x*x%MOD;
        m/=2;
    }
    return ans;
}
LL CC(int n,int m)
{   if(m==0)return 1;
     //cout<<jc[n]<<" "<<fjc[m]<<endl;
    return jc[n]*fjc[m]%MOD*fjc[n-m]%MOD;
}
int main()
{
    k=0;
    memset(is,true,sizeof(is));
    is[0]=is[1]=0;
    for(int i=2;i<=N;i++)
    {
        if(is[i])
        {
            prime[++k]=i;
            for(int j=i*i;j<=N;j+=i)is[j]=false;
        }
    }
    jc[0]=1;
    for(int i=1;i<=N;i++)
    {
        jc[i]=jc[i-1]*i%MOD;
        fjc[i]=quickmi(jc[i],MOD-2);  //阶乘的逆模元,费马小定理
        //if(i<20)
        //cout<<jc[i]<<" "<<fjc[i]<<endl;
    }
    int x;
    while(scanf("%d",&n)!=EOF)
    {
        mp.clear();
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&x);
            addm(x);
        }
        LL ans=1;
        map<int,int>::iterator it;
        for(it=mp.begin();it!=mp.end();it++)
        {
            x=it->second;
           //printf("%d\n",x);
            ans=ans*CC(n+x-1,n-1)%MOD;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值