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.
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).
Print one integer — the product of all divisors of n modulo 109 + 7.
2 2 3
36
3 2 3 2
1728
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.
因为所有因子都是要乘起来,所以算出每个质因子(以及它的幂)乘了几次。先预处理出每个质因子出现的次数, num[i]表示i这个质因子出现了num[i]次,那么要算j这个质因子乘的次数 p = (num[k] + 1)(k为所有质因子除了j)的乘积.
那么接下来要算j^p % MOD, 因为p会很大所以根据费马小定理j^p%MOD = j^(p%(MOD-1))%MOD;
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#define maxn 200005
#define INF 1e15
#define MOD 1000000007
typedef long long ll;
using namespace std;
int num[maxn];
ll k1[maxn], k2[maxn];
ll pow_mod(ll p, ll m){
ll ans = 1;
while(m){
if(m&1)(ans *= p) %= MOD;
(p *= p) %= MOD;
m >>= 1;
}
return ans;
}
int main(){
// freopen("in.txt", "r", stdin);
int m, a, maxs = 0;
scanf("%d", &m);
for(int i = 0; i < m; i++){
scanf("%d", &a);
maxs = max(maxs, a);
num[a]++;
}
k1[1] = 1;
for(int i = 2; i <= maxs; i++){
if(num[i])
k1[i] = k1[i-1] * (num[i] + 1)% (MOD - 1);
else
k1[i] = k1[i-1];
}
k2[maxs+1] = 1;
for(int i = maxs; i >= 2; i--){
if(num[i])
k2[i] = k2[i+1] * (num[i] + 1) % (MOD - 1);
else
k2[i] = k2[i+1];
}
ll ans = 1;
for(int i = 2; i <= maxs; i++){
if(num[i]){
ll p1 = k1[i-1] * k2[i+1] % (MOD - 1), p2 = 1;
for(int j = 1; j <= num[i]; j++){
(p2 *= i) %= MOD;
(ans *= pow_mod(p2, p1)) %= MOD;
}
}
}
printf("%I64d\n", ans);
return 0;
}