codeforces 615D

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.

Sample test(s)
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.





/*
题意:给出n个素数,求素数的乘积的约数的乘积在MOD上一个数
逆元
a^n%m= a^(n mod(m-1))%m;
*/
#include<bits/stdc++.h>
using namespace std;
typedef __int64 LL;
const   LL maxn = 200010;
const  LL mod= (1e9+7);
LL rec[maxn];
LL c[maxn];
LL l[maxn];
LL r[maxn];
LL _mod(LL  a, LL  b)
{
 LL  ans =1;
    while(b)
    {
        if(b&1)
        {
            ans = (ans%mod)*(a%mod)%mod;

        }
        b>>=1;
        a= (a%(mod))*(a%(mod))%mod;
    }
    return ans ;
}
int main()
{
    int n;
    scanf("%d",&n);
    memset(c,0,sizeof(c));
    int cot = 1;
    int x;
    for(int i = 1; i<=n; i++)
    {
        scanf("%d",&x);
        if(!c[x])
        {
            rec[cot++] = x;
            c[x]++;
        }
        else
        {
            c[x]++;
        }
    }
    cot--;
    l[0]= 1;
    r[cot+1] =1;
    for(int i = 1; i<=cot; i++)
    {
        l[i] = (l[i-1]%(mod-1)*(c[rec[i]]+1)%(mod-1))%(mod-1);//l[i]是1--i之间因子的组合种数 
    }
    for(int i = cot; i>=1; i--)
    {
        r[i] = ((r[i+1]%(mod-1))*(c[rec[i]]+1)%(mod-1))%(mod-1);//r[i]是i--r之间的因子的组合种树 
    }
    long long ans = 1;
    for(int i =1 ; i<=cot; i++)
    {
        if(c[rec[i]])
        {
            LL num =(l[i-1]*r[i+1])%(mod-1)*(((c[rec[i]]+1)*(c[rec[i]])/2)%(mod-1))%(mod-1);//考虑每个因子所做的贡献
             num = num%(mod-1);
            ans = (ans%(mod)*(_mod(rec[i],num))%mod)%mod;
            //cout<<ans<<endl;
        }
    }
    cout<<ans%mod<<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值