hdu5525Product+约数的乘积

Problem Description
Given a number sequence A1,A2….An,indicating N=∏ni=1iAi.What is the product of all the divisors of N?

Input
There are multiple test cases.
First line of each case contains a single integer n.(1≤n≤105)
Next line contains n integers A1,A2….An,it’s guaranteed not all Ai=0.(0≤Ai≤105).
It’s guaranteed that ∑n≤500000.

Output
For each test case, please print the answer module 109+7 in a line.

Sample Input

4
0 1 1 0
5
1 2 3 4 5

Sample Output

36
473272463

Source
BestCoder Round #61 (div.2)

Recommend
hujie | We have carefully selected several similar problems for you: 5906 5905 5903 5900 5899

方法同http://blog.csdn.net/xtulollipop/article/details/52706262
http://codeforces.com/problemset/problem/615/D

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

打个表。。然后每输入一个数,直接质因数分解就好了。。
orz..坑质因数的个数可能很大。。求约数个数的时候,注意细节处理,,(不知所错的。。wa了6,7发。。)

#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;
}
int prime[100005];
bool visit[100005];
int cnt=0;
void getprime(){
    memset(visit,false,sizeof(visit));
    for(int i=2;i<=100005;i++){
        if(visit[i]==false){
            prime[cnt++]=i;
            for(int j=i+i;j<=100005;j+=i) visit[j]=true;
        }
    }
}

map<int,LL>Q;
map<int,LL>::iterator it;

LL a[100006];

void add(int x,LL p){
    for(int i=0;prime[i]*prime[i]<=x;i++){
        while(x%prime[i]==0){
            a[prime[i]]+=p;
            x/=prime[i];
        }
    }
    if(x>1) a[x]+=p;
}
int main(){
    int n;
    LL x;
    getprime();
    while(cin>>n){
        Q.clear();
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++){
            cin>>x;
            add(i,x);
        }
        for(int i=2;i<=n;i++) {
            if(a[i]!=0) Q[i]=a[i];
        }
       /* for(it=Q.begin();it!=Q.end();it++){
            cout<<it->first<<" "<<it->second<<endl;
        }*/
        LL all=1;
        for(it=Q.begin();it!=Q.end();it++){
            all*=((it->second)+1)%mod2;//wa了5,6发,取膜啊!
            all%=mod2;
        }
        LL ans=1;
        for(it=Q.begin();it!=Q.end();it++){
            LL p=1LL*(it->second)%mod2;//取膜啊!
            //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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值