zoukankan      html  css  js  c++  java
  • [数论] HDU 6833 A very easy math problem

    题目大意

    给定正整数 (n,x,k),求

    [sum_{a_1=1}^{n}sum_{a_2=1}^ndotsbsum_{a_x=1}^nleft(prod_{j=1}^xa_j^k ight)fleft(gcdleft(a_1,a_2,dots,a_x ight) ight)cdot gcdleft(a_1,a_2,dots,a_x ight) ]

    如果存在正整数 (k(k>1)),并且 (k^2|x),那么 (f(x)=0),否则 (f(x)=1)

    (1leq kleq 10^9,1leq xleq 10^9,1leq nleq 2 imes10^5)

    题解

    注意到 (f(x)) 的定义,显然 (f(x)=mu^2(x))
    那么就是要求

    [sum_{a_1=1}^{n}sum_{a_2=1}^ndotsbsum_{a_x=1}^nleft(prod_{j=1}^xa_j^k ight)mu^2left(gcdleft(a_1,a_2,dots,a_x ight) ight)cdot gcdleft(a_1,a_2,dots,a_x ight) ]

    首先枚举gcd

    [sum_{d=1}^nsum_{a_1=1}^{n}sum_{a_2=1}^ndotsbsum_{a_x=1}^nleft(prod_{j=1}^xa_j^k ight)mu^2left(d ight)cdot d [d=gcdleft(a_1,a_2,dots,a_x ight)] ]

    [sum_{d=1}^nmu^2left(d ight)dsum_{a_1=1}^{n}sum_{a_2=1}^ndotsbsum_{a_x=1}^nleft(prod_{j=1}^xa_j^k ight)[d=gcdleft(a_1,a_2,dots,a_x ight)] ]

    [sum_{d=1}^nmu^2left(d ight)dsum_{a_1=1}^{n/d}sum_{a_2=1}^{n/d}dotsbsum_{a_x=1}^{n/d}left(prod_{j=1}^x(a_jd)^k ight)[gcdleft(a_1,a_2,dots,a_x ight)=1] ]

    [sum_{d=1}^nmu^2left(d ight)dsum_{a_1=1}^{n/d}sum_{a_2=1}^{n/d}dotsbsum_{a_x=1}^{n/d}left(prod_{j=1}^x(a_jd)^k ight)sum_{p|gcd(a_1,a_2,dots,a_x)}mu(p) ]

    [sum_{d=1}^nmu^2left(d ight)d^{kx+1}sum_{a_1=1}^{n/d}sum_{a_2=1}^{n/d}dotsbsum_{a_x=1}^{n/d}left(prod_{j=1}^xa_j^k ight)sum_{p|gcd(a_1,a_2,dots,a_x)}mu(p) ]

    枚举 (p)

    [sum_{d=1}^nmu^2left(d ight)d^{kx+1}sum_{p=1}^{n/d}mu(p)sum_{a_1=1}^{n/dp}sum_{a_2=1}^{n/dp}dotsbsum_{a_x=1}^{n/dp}left(prod_{j=1}^x(a_jp)^k ight) ]

    [sum_{d=1}^nmu^2left(d ight)d^{kx+1}sum_{p=1}^{n/d}mu(p)p^{kx}sum_{a_1=1}^{n/dp}sum_{a_2=1}^{n/dp}dotsbsum_{a_x=1}^{n/dp}left(prod_{j=1}^xa_j^k ight) ]

    由于

    [sum_{a_1=1}^{n}sum_{a_2=1}^ndotsbsum_{a_x=1}^nleft(prod_{j=1}^xa_j^k ight)=left(sum_{i=1}^ni^k ight)^x ]

    [sum_{d=1}^nmu^2left(d ight)d^{kx+1}sum_{p=1}^{n/d}mu(p)p^{kx}left(sum_{i=1}^{n/dp}i^k ight)^x ]

    (T=dp),得

    [sum_{T=1}^{n}T^{kx}left(sum_{i=1}^{n/T}i^k ight)^xsum_{d|T}mu^2(d)mu(frac{T}{d})d ]

    [g(T)=sum_{d|T}mu^2(d)mu(frac{T}{d})d ]

    则原式变为

    [sum_{T=1}^{n}T^{kx}left(sum_{i=1}^{n/T}i^k ight)^xg(T) ]

    对于 (Tin [1,n]) 的所有 (g(T)),我们可以在 (O(nlog n)) 的时间预处理出。
    最后对于每一组询问,可以在 (O(sqrt n)) 的时间内通过数论分块求出。
    (t) 为数据组数,则时间复杂度为 (O(nlog n+tsqrt n))

    Code

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <cstdio>
    #include <vector>
    using namespace std;
    
    #define RG register int
    #define LL long long
    
    template<typename elemType>
    inline void Read(elemType &T){
        elemType X=0,w=0; char ch=0;
        while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
        while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
        T=(w?-X:X);
    }
    
    const LL MOD=1000000007LL;
    const int maxn=200000;
    LL g[maxn+5],h[maxn+5],Mu[maxn+5];
    bool not_Prime[maxn+5];
    vector<int> Prime;
    LL K,X;
    int T,n;
    
    LL ExPow(LL b,LL n){
        LL x=1,Power=b%MOD;
        while(n){
            if(n&1) x=x*Power%MOD;
            Power=Power*Power%MOD;
            n>>=1;
        }
        return x;
    }
    
    void Get_Mu(int Len){
        Mu[1]=1;
        not_Prime[1]=1;
        int Size=0;
        for(RG i=2;i<=Len;i++){
            if(!not_Prime[i]){
                Prime.push_back(i);
                Mu[i]=-1;++Size;
            }
            for(RG j=0;j<Size;j++){
                int mid=Prime[j]*i;
                if(mid>Len) break;
                not_Prime[mid]=1;
                if(i%Prime[j]==0){
                    Mu[i*Prime[j]]=0;
                    break;
                }
                Mu[mid]=-Mu[i];
            }
        }
        return;
    }
    
    void Init(){
        Get_Mu(maxn);
        for(RG i=1;i<=maxn;++i)
            for(RG j=i;j<=maxn;j+=i)
                g[j]=((g[j]+Mu[i]*Mu[i]*Mu[j/i]*i%MOD)%MOD+MOD)%MOD;
        for(RG i=1;i<=maxn;++i){
            LL temp=ExPow(ExPow(i,K),X);
            g[i]=(g[i-1]+g[i]*temp%MOD)%MOD;
            h[i]=(h[i-1]+ExPow(i,K))%MOD;
        }
        return;
    }
    
    LL Solve(){
        LL Res=0;
        for(RG L=1,R;L<=n;L=R+1){
            R=n/(n/L);
            LL temp=ExPow(h[n/L],X);
            Res=((Res+temp*(g[R]-g[L-1])%MOD)%MOD+MOD)%MOD;
        }
        return Res;
    }
    
    int main(){
        Read(T);Read(K);Read(X);
        Init();
        while(T--){
            Read(n);
            printf("%lld
    ",Solve());
        }
        return 0;
    }
    
  • 相关阅读:
    linux十九压缩解压
    linux第十八dd命令
    【51单片机】数据类型
    【博客园】
    【C++】简介与环境的搭建
    【树莓派】安装TeamViewer
    【树莓派】Makefile的编写
    【cJSON库】cJSON库的使用
    【树莓派】忘记系统用户密码,如何重置密码
    【树莓派】树莓派与PC机通信
  • 原文地址:https://www.cnblogs.com/AEMShana/p/13468739.html
Copyright © 2011-2022 走看看