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 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.
题意:给你 n 个素数,让你求它们相乘之后的数的因子之积
思路:首先,我们知道一个数
不含
最后总结我们需要进行的两个步骤:
1.
sum=∏ki=1(1+ci)%(2mod−2)
2.
ans=∏ki=1pci⋅sum2i%mod
ac代码:
/* ***********************************************
Author : AnICoo1
Created Time : 2016-08-12-09.38 Friday
File Name : C:\Users\lenovo\Documents\2016-8-12.cpp
LANGUAGE : C++
Copyright 2016 clh All Rights Reserved
************************************************ */
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mod 1000000007
#define mem(x,y) memset(x,(y),sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
ll cnt[MAXN];
int main()
{
int n;scanf("%d",&n);mem(cnt,0);
for(int i=1;i<=n;i++)
{
int p;scanf("%d",&p);
cnt[p]++;
}
ll sum=1;
for(int i=1;i<=200000;i++)
{
if(cnt[i])
sum=(sum*(1+cnt[i]))%(mod*2-2);
}
ll ans=1;
for(int i=1;i<=200000;i++)
if(cnt[i])
ans=(ans*powmod(i,cnt[i]*sum/2,mod))%mod;
printf("%I64d\n",ans);
return 0;
}