• P3312 [SDOI2014]数表


    P3312 [SDOI2014]数表

    (sum_{i=1}^nsum_{j=1}^msigma(gcd(i,j))[sigma(gcd(i,j)<=a)])

    (f(d)=sum_{i=1}^nsum_{j=1}^m[gcd(i,j)=d])

    (F(d)=sum_{i=1}^nsum_{j=1}^m [|dgcd(i,j)]=sum_{d|k}f(k))

    (f(d)=sum_{d|k}mu(dfrac{k}{d})F(k)=sum_{d|k}mu(leftlfloorfrac{k}{d} ight floor)leftlfloorfrac{n}{k} ight floorleftlfloorfrac{m}{k} ight floor)

    (Ans=sum_{i=1}^{min(n,m)}sigma(i)f(i))

    (=sum_{i=1}^{min(n,m)}sigma(i)sum_{i|k}mu(leftlfloorfrac{k}{i} ight floor)leftlfloorfrac{n}{k} ight floorleftlfloorfrac{m}{k} ight floor)

    (=sum_{k=1}^{min(n,m)}leftlfloorfrac{n}{k} ight floorleftlfloorfrac{m}{k} ight floorsum_{i|k}mu(leftlfloorfrac{k}{i} ight floor)sigma(i))

    后半部分预处理筛一遍(sum_{i|k}mu(leftlfloorfrac{k}{i} ight floor)sigma(i)),前面分块一下,别忘了还有限制条件([sigma(gcd(i,j)<=a)]),丢到树状数组里就行了

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int maxn=1e5+9;
    inline int Read(){
        int x=0,f=1; char c=getchar();
        while(c<'0'||c>'9'){
            if(c=='-') f=-1; c=getchar();
        }
        while(c>='0'&&c<='9')
            x=(x<<3)+(x<<1)+c-'0',c=getchar();
        return x*f;
    }
    int mu[maxn],prime[maxn];
    bool visit[maxn];
    inline void F_phi(int N){
        mu[1]=1; int tot(0);
        for(int i=2;i<=N;++i){
            if(!visit[i]){
                prime[++tot]=i,
                mu[i]=-1;
            }
            for(int j=1;j<=tot&&i*prime[j]<=N;++j){
                visit[i*prime[j]]=true;
                if(i%prime[j]==0)
                    break;
                else
                    mu[i*prime[j]]=-mu[i];
            }
        }
    }
    struct _F{
        int id;
        LL val;
    }F[maxn];
    inline bool cmp_F(_F x,_F y){
        return x.val<y.val;
    }
    
    struct Qy{
        int n,m,a,id;
    }q[maxn];
    inline bool cmp_Q(Qy x,Qy y){
        return x.a<y.a;
    }
    
    int sum[maxn];
    inline int Lowbit(int i){
        return i&(-i);
    }
    inline void Add(int i,int val){
        for(;i<=100000;i+=Lowbit(i))
            sum[i]+=val;
    }
    inline int Query(int i){
        int num(0);
        for(;i;i-=Lowbit(i))
            num+=sum[i];
        return num;
    }
    inline int Calc(int n,int m){
        int num(0);
        if(n>m)
            swap(n,m);
        for(int l=1,r;l<=n;l=r+1){
            r=min(n/(n/l),(m/(m/l)));
            num+=(n/l)*(m/l)*(Query(r)-Query(l-1));
        }
        return num;
    }
    
    int ans[maxn];
    int main(){
        F_phi(100000);
        for(int i=1;i<=100000;++i){
            F[i].id=i;
            for(int j=1;j*i<=100000;++j)
                F[j*i].val+=i;
        }
        sort(F+1,F+1+100000,cmp_F);
        
        int T=Read();
        for(int i=1;i<=T;++i){
            int n=Read(),m=Read(),a=Read();
            q[i]=(Qy){n,m,a,i};
        }
        sort(q+1,q+1+T,cmp_Q);
        
        int now(0);
        for(int i=1;i<=T;++i){
            while(now<100000&&F[now+1].val<=q[i].a){
                ++now;
                for(int j=1;j*F[now].id<=100000;++j)
                    Add(j*F[now].id,mu[j]*F[now].val);
            }
            ans[q[i].id]=Calc(q[i].n,q[i].m);
        }
        
        for(int i=1;i<=T;++i)
            printf("%d
    ",ans[i]&0x7fffffff);
        return 0;
    }/*
    2
    4 4 3
    10 10 5
    
    20
    148
    */
    
  • 相关阅读:
    JSON 序列化类 南京酷得软件
    哈哈哈哈哈哈 找回记忆
    Presto
    (转)在Total Commander下使用SVN
    在ubuntu12.04,64位中安装lnmp一键包mysql的问题
    阿里云服务器上搭建php环境+redis
    在ubuntu12.04,64位中安装nginx+php+redis+mysql
    Redis篇:单线程I/O模型
    工具篇:apachehttpClient 和 jdk11HttpClient的使用
    技能篇:关于缓存数据的一致性探讨
  • 原文地址:https://www.cnblogs.com/y2823774827y/p/10227373.html
Copyright © 2020-2023  润新知