Codeforces Round #338 (Div. 2)-D. Multipliers

原题链接

D. Multipliers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
input
2
2 3
output
36
input
3
2 3 2
output
1728
Note

In the first sample n = 2·3 = 6. The divisors of 6 are 123 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 12346 and 121·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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值