題目鏈接:https://codeforc.es/contest/615/problem/D
題目大意:根據唯一分解定理,給定關於的所有素因子,計算關於的所以因數乘積。
思路:記錄每個素因子出現的次數,預處理素因子的次數+1的前綴積和後綴積。
枚舉每個素因子在答案中的貢獻,對於每個素因子來說,對應貢獻爲:
這裏運用一下歐拉降冪就了。
AC代碼:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=2e5+100;
ll qpow(ll x,ll y)
{
ll ans=1;
while(y>0){
if(y&1){
ans=ans*x%mod;
}
y>>=1;
x=x*x%mod;
}
return ans;
}
ll pre[maxn],suf[maxn];
map<ll ,ll>mp;
set<ll>se;
ll p[maxn];
ll c[maxn];
int main()
{
ll m;
cin>>m;
ll inv_2=qpow(2,mod-2);
ll tmp;
for(int i=1;i<=m;i++){
cin>>tmp;
se.insert(tmp);
mp[tmp]++;
}
int cnt=1;
for(auto &it:se){
p[cnt]=it;
c[cnt++]=mp[it];
}
ll phi=mod-1;
pre[0]=1;
for(int i=1;i<cnt;i++){
pre[i]=pre[i-1]*(c[i]+1)%phi;
}
suf[cnt]=1;
for(int i=cnt-1;i>0;i--){
suf[i]=suf[i+1]*(c[i]+1)%phi;
}
ll ans=1;
for(int i=1;i<cnt;i++){
ll t1=c[i]*(c[i]+1)/2%phi;
t1=t1*pre[i-1]%phi*suf[i+1]%phi;
t1+=phi;//歐拉降冪的公式
ans=ans*qpow(p[i],t1)%mod;
}
cout<<ans<<endl;
return 0;
}