codeforces 396A On Number of Decompositions into Multipliers

http://www.elijahqi.win/2018/03/08/codeforces-396a/
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 modulo 1000000007 (109 + 7).

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

Output
In a single line print a single number k — the number of distinct decompositions of number m into n ordered multipliers modulo 1000000007 (109 + 7).

Examples
input

Copy
1
15
output
1
input

Copy
3
1 1 2
output
3
input

Copy
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 into n ordered multipliers is a cortege of positive integers b = {b1, b2, … bn} such that . Two decompositions b and c are considered different, if there exists index i such that bi ≠ ci.

考虑把每个a分解质因数 统计每种质因数的个数 那么如果直接考虑会有重复的 不妨我们考虑把这些质因数如何放入我的位置即可吧 那么相当于每种质数我考虑放入n个位置的方案数吧利用隔板法 因为每个位置不必有 那么加设第i种质数有k个 那么相当于在k+n-1个空位里插入n-1个板的方案数
 [ans=ti=1C(n+ki1,n1) ]   [ a n s = ∏ i = 1 t C ( n + k i − 1 , n − 1 )   ]

#include<map>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
#define mod 1000000007
using namespace std;
map<int,int> mm;
map<int,int>::iterator it;
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0,f=1;char ch=gc();
    while(ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=gc();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=gc();
    return x*f;
}
int inv[16500],g[16500],n,m;
int main(){
//  freopen("cf396a.in","r",stdin);
    n=read();for (int i=1;i<=n;++i) {
        int xx=read(),x=xx;
        for (int j=2;j<=sqrt(xx);++j){
            if (x%j) continue;
            while(x%j==0) ++mm[j],x/=j;
        }if (x>1) ++mm[x];
    }g[0]=1;
    for (int i=1;i<=15010;++i) g[i]=(ll)g[i-1]*i%mod;inv[1]=1;inv[0]=1;
    for (int i=2;i<=15010;++i) inv[i]=(ll)inv[mod%i]*(mod-mod/i)%mod;
    for (int i=2;i<=15010;++i) inv[i]=(ll)inv[i-1]*inv[i]%mod;ll ans=1;
    //for (int i=1;i<=10;++i) printf("%d\n",inv[i]);
    for (it=mm.begin();it!=mm.end();++it){
        //printf("%d %d\n",(*it).first,(*it).second);
        int down=n+(*it).second-1,up=n-1;
        (ans*=(ll)g[down]*inv[down-up]%mod*inv[up]%mod)%=mod;
    }printf("%lld\n",ans);
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值