cf615Multipliers+N的约数的乘积

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=pa11pa22pann
考虑 pa11 对于约数积的贡献,首先会在后面所有 ni=2(ai+1) 个约数中出现
pa11p01p11pa11,p1:
Ep1=(p01p11pa11)ni=2(ai+1)
   =(pa1(a1+1)2)ni=2(ai+1)
   =pa1ni=1(ai+1)2
Epi=paini=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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值