Problem Description
Given a number sequence A1,A2….An,indicating N=∏ni=1iAi.What is the product of all the divisors of N?
Input
There are multiple test cases.
First line of each case contains a single integer n.(1≤n≤105)
Next line contains n integers A1,A2….An,it’s guaranteed not all Ai=0.(0≤Ai≤105).
It’s guaranteed that ∑n≤500000.
Output
For each test case, please print the answer module 109+7 in a line.
Sample Input
4
0 1 1 0
5
1 2 3 4 5
Sample Output
36
473272463
Source
BestCoder Round #61 (div.2)
Recommend
hujie | We have carefully selected several similar problems for you: 5906 5905 5903 5900 5899
方法同http://blog.youkuaiyun.com/xtulollipop/article/details/52706262
http://codeforces.com/problemset/problem/615/D
设这个数为X=pa11⋅pa22⋯pann
考虑
pa11
对于约数积的贡献,首先会在后面所有
∏ni=2(ai+1)
个约数中出现
且pa11取值有p01、p11⋯pa11,那么p1的贡献:
Ep1=(p01∗p11⋯pa11)∏ni=2(ai+1)
=(pa1⋅(a1+1)2)∏ni=2(ai+1)
=pa1⋅∏ni=1(ai+1)2
同理Epi=pai⋅∏ni=1(ai+1)2i
so
ans=∏Epi
同样的有连个地方要注意,一个是
∏ni=2(ai+1)
可能会很大,,得用费马小定理
ap%m=aφ(m)+p%φ(m)%m
第二个就是有除法的膜。
ab%c=a%bcc
打个表。。然后每输入一个数,直接质因数分解就好了。。
orz..坑质因数的个数可能很大。。求约数个数的时候,注意细节处理,,(不知所错的。。wa了6,7发。。)
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define maxn 200000
const LL mod1=1000000007;
const LL mod2=2*(mod1-1);
LL quick_mod(LL a,LL n,LL mod){
LL ans=1;
while(n){
if(n&1) ans=ans*a%mod;
a=a*a%mod;
n>>=1;
}
return ans;
}
int prime[100005];
bool visit[100005];
int cnt=0;
void getprime(){
memset(visit,false,sizeof(visit));
for(int i=2;i<=100005;i++){
if(visit[i]==false){
prime[cnt++]=i;
for(int j=i+i;j<=100005;j+=i) visit[j]=true;
}
}
}
map<int,LL>Q;
map<int,LL>::iterator it;
LL a[100006];
void add(int x,LL p){
for(int i=0;prime[i]*prime[i]<=x;i++){
while(x%prime[i]==0){
a[prime[i]]+=p;
x/=prime[i];
}
}
if(x>1) a[x]+=p;
}
int main(){
int n;
LL x;
getprime();
while(cin>>n){
Q.clear();
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++){
cin>>x;
add(i,x);
}
for(int i=2;i<=n;i++) {
if(a[i]!=0) Q[i]=a[i];
}
/* for(it=Q.begin();it!=Q.end();it++){
cout<<it->first<<" "<<it->second<<endl;
}*/
LL all=1;
for(it=Q.begin();it!=Q.end();it++){
all*=((it->second)+1)%mod2;//wa了5,6发,取膜啊!
all%=mod2;
}
LL ans=1;
for(it=Q.begin();it!=Q.end();it++){
LL p=1LL*(it->second)%mod2;//取膜啊!
//cout<<p<<endl;
LL temp=p*all%mod2;
temp/=2;
temp+=mod1-1;
//cout<<temp<<endl;
ans*=quick_mod((it->first),temp,mod1);
ans%=mod1;
//cout<<ans<<endl;
}
cout<<ans<<endl;
}
return 0;
}