Description
Ayrat has number n, represented as it’s prime factorization pi of size m, i.e. n = p1·p2·…·pm. Ayrat got secret information that that the product of all divisors of n taken modulo 109 + 7 is the password to the secret data base. Now he wants to calculate this value.
Input
The first line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of primes in factorization of n.
The second line contains m primes numbers pi (2 ≤ pi ≤ 200 000).
Output
Print one integer — the product of all divisors of n modulo 109 + 7.
Sample Input
Input
2
2 3
Output
36
Input
3
2 3 2
Output
1728
Hint
In the first sample n = 2·3 = 6. The divisors of 6 are 1, 2, 3 and 6, their product is equal to 1·2·3·6 = 36.
In the second sample 2·3·2 = 12. The divisors of 12 are 1, 2, 3, 4, 6 and 12. 1·2·3·4·6·12 = 1728.
设这个数为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
#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;
}
map<int,int>Q;
map<int,int>::iterator it;
int main(){
int n,x;
while(cin>>n){
Q.clear();
for(int i=1;i<=n;i++){
cin>>x;
Q[x]++;
}
LL all=1;
for(it=Q.begin();it!=Q.end();it++){
all*=(it->second)+1;
all%=mod2;
}
LL ans=1;
for(it=Q.begin();it!=Q.end();it++){
LL p=1LL*(it->second);
//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;
}