Codeforces Round #232 (Div. 2) C. On Number of Decompositions into Multipliers 之我为何如此菜

C. On Number of Decompositions into Multipliers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 modulo1000000007 (109 + 7).

Sample test(s)
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 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.


题意:

有n(n<=500)个数ai(ai<=10^9),令m=a1*a2*..*an ,求把m划分成n个数相乘的划分种数。

思路:

分析最后的结果,我们总是要得到 m=a1*a2*..*an,而每个不同的ai对应着一种情况,要使情况不重复,想到对ai因式分解,每个ai都是几个素数因子的积,而不同的素数因子之间又是互不影响的,问题等价为将每个素数因子放入n个盒子中(盒子可以为空,用1补),有多少种放法,然后将每个素数因子得到的个数相乘就是答案了。

求放法的总数这要用到组合数学的知识,素数因子a有b个,要将这b个分成n部分,可以看做有b+n-1个盒子,从中取n-1个(相当于隔板),剩下的盒子放入b个a,这样就将这b个a分成了n部分,中间空的为1。

感想:

遇到数学就被虐成狗,我太菜了。


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 1005
#define MAXN 20005
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
typedef long long ll;
using namespace std;

ll n,m,ans,cnt,tot,flag;
int C[17000][500];
map<ll,ll>mp;
map<ll,ll>::iterator it;

int main()
{
    ll i,j,t;
    for(i=0;i<17000;i++)
    {
        C[i][0]=1;
    }
    for(i=1;i<17000;i++)
    {
        for(j=1;j<500;j++)
        {
            C[i][j]=C[i-1][j]+C[i-1][j-1];
            C[i][j]%=mod;
        }
    }
    while(cin>>n)
    {
        mp.clear();
        ll x,y;
        for(i=1;i<=n;i++)
        {
            cin>>t;
            y=sqrt(t+0.5);
            for(j=2;j<=y&&t>1;j++)
            {
                if(t%j==0)
                {
                    while(t%j==0)
                    {
                        t/=j;
                        mp[j]++;
                    }
                }
            }
            if(t>1) mp[t]++;
        }
        ans=1;
        for(it=mp.begin();it!=mp.end();it++)
        {
            t=it->second;
            x=t+n-1;
            ans*=C[x][n-1];
            ans%=mod;
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*
2
5 7
*/





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值