Codeforces#232 A

6 篇文章 0 订阅

A

A. 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).


所有数质因数分解,得到的质因数放一起就是M啦。。然后就可以XXOO了。

博文写的有点慢。

#include<stdio.h>
#include<string.h>
#include<iostream>

using namespace std;

#define mod 1000000007

int p[200000],a[200000],num[200000],pnum,tnum,m,n;
long long tmp,oo,mi,ans;

void lis(){
    int i,j;
    pnum = 0;
    memset(p,0,sizeof(p));
    memset(a,0,sizeof(a));
    for(i = 2;i < 100000; i++)
    if(!a[i])
    {
        p[pnum++] = i;
        for(j = 2*i;j < 100000; j+=i)
            a[j] = 1;
    }
    tnum = pnum;
}

int main()
{
    lis();
    int t,i,j,x;
    cin >> t;
    m = t-1;
    memset(num,0,sizeof(num));
    for(i = 1; i <= t;i++)
        {
            cin >> x;
            for(j = 0;j < pnum; j++)
            {
                if(x%p[j]==0)
                {
                    while(x%p[j]==0)
                    {
                        num[j]++;
                        x /= p[j];
                    }
                }
                if(x<p[j])
                    break;
            }
            if(x!=1)
                {
                    int k = 0;
                    for(j = pnum; j < tnum; j++)
                        if(p[j]==x)
                           {
                               k = 1;
                               num[j]++;
                               break;
                           }
                    if(k==0)
                    {
                        p[tnum] = x;
                        num[tnum]++;
                        tnum++;
                    }
                }
        }
    if(m==0)
    {
        cout << 1 << endl;
        return 0;
    }
    ans = 1;
    for(i = 0; i < tnum; i++)
        if(num[i]!=0)
            {
                n = num[i]+m;
                for(j = n-m+1; j <= n; j++)
                    ans = (ans*j)%mod;
                tmp = 1;
                for(j = 1; j <= m; j++)
                    tmp = (tmp*j)%mod;
                tmp = tmp%mod;
                mi = 1000000005;
                oo = 1;
                while(mi)
                {
                    if(mi%2==1)
                       oo = (oo*tmp)%mod;
                    tmp = (tmp*tmp)%mod;
                    mi /= 2;
                }
                ans = (ans*oo)%mod;
            }
    ans = ans%mod;
    cout << ans << endl;
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值