zoukankan      html  css  js  c++  java
  • hdu 5525 Product 数论算贡献

    Product

    Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)



    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.(1n105)
    Next line contains n integers A1,A2....An,it's guaranteed not all Ai=0.(0Ai105).
    It's guaranteed that n500000.
     
    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
     
    题意:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=2e5+10,M=4e6+10,inf=2147483647;
    const ll INF=1e18+10,mod=1e9+7;
    
    ///   数组大小
    int prime(int n)
    {
        if(n<=1)
        return 0;
        if(n==2)
        return 1;
        if(n%2==0)
        return 0;
        int k, upperBound=n/2;
        for(k=3; k<=upperBound; k+=2)
        {
            upperBound=n/k;
            if(n%k==0)
                return 0;
        }
        return 1;
    }
    
    vector<int>p;
    int si[N];
    void init()
    {
        for(int i=2;i<=100000;i++)
            if(prime(i))
            p.push_back(i);
    }
    ll quick(ll a,ll b,ll c)
    {
        ll ans=1;
        while(b)
        {
            if(b&1)ans=(ans*a)%c;
            b>>=1;
            a=(a*a)%c;
        }
        return ans;
    }
    int main()
    {
        init();
        int n;
        while(~scanf("%d",&n))
        {
            memset(si,0,sizeof(si));
            for(int i=1;i<=n;i++)
            {
                int z;
                int x=i;
                scanf("%d",&z);
                for(int j=0;j<p.size();j++)
                {
                    if(1LL*p[j]*p[j]>x)break;
                    if(x==1)break;
                    while(x%p[j]==0)
                    {
                        si[j]+=z;
                        si[j]=(si[j])%(2*(mod-1));
                        x/=p[j];
                    }
                }
                if(x!=1)
                {
                    int pos=lower_bound(p.begin(),p.end(),x)-p.begin();
                    si[pos]+=z;
                }
            }
            ll sum=1;
            for(int i=0;i<p.size();i++)
            {
                sum*=(si[i]+1);
                sum%=(2*(mod-1));
            }
            //cout<<sum<<endl;
            ll ans=1;
            for(int i=0;i<p.size();i++)
            {
                ans=(ans*quick(p[i],((sum*si[i])%(2*(mod-1)))/2,mod))%(mod);
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    一个GOOD的Idea需要伯乐发觉-致敬错过的IDEA
    企业增量发布项目-个人步骤
    JAVA 发送邮件代码---发送HTML内容
    JAVA 发送邮件代码---发送文本内容: 内容使用 进行换行
    Myeclipse8.5开发-安装一:Myeclipse8.5注册码生成程序
    Myeclipse8.5开发-插件安装二:安装findbugs方法
    页面布局
    Flex布局(CSS Flexbox)
    CSS垂直居中的11种实现方式
    CSS3中的px,em,rem,vh,vw辨析
  • 原文地址:https://www.cnblogs.com/jhz033/p/6686043.html
Copyright © 2011-2022 走看看