A
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).
The first line contains positive integer n (1 ≤ n ≤ 500). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
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;
}