P1829 [国家集训队]Crash的数字表格 / JZPTAB

Posted y2823774827y

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了P1829 [国家集训队]Crash的数字表格 / JZPTAB相关的知识,希望对你有一定的参考价值。

P1829 [国家集训队]Crash的数字表格 / JZPTAB

(Ans=sum_{i=1}^{n}sum_{j=1}^{m}frac{ij}{gcd(i,j)})

思考把(sum_{d|n}mu(d)=[n=1])带进去

(Ans=sum_{d=1}^{min(n,m)}sum_{i=1}^{n}sum_{j=1}^{m}[gcd(i,j)=d]frac{ij}{d})

(Ans=sum_{d=1}^{min(n,m)}dsum_{i=1}^{lfloorfrac{n}{d} floor}sum_{j=1}^{lfloorfrac{m}{d} floor}[gcd(i,j)=1]ij)

至此,我们把式变成:

(Ans=sum_{d=1}^{min(n,m)}dsum_{i=1}^{lfloorfrac{n}{d} floor}sum_{j=1}^{lfloorfrac{m}{d} floor}sum_{x|gcd(i,j)}mu(x)ij)

我们来枚举(x)消掉(sum_{x|gcd(i,j)})

(Ans=sum_{d=1}^{min(n,m)}dsum_{x=1}^{min(lfloorfrac{n}{d} floor,lfloorfrac{m}{d} floor)}mu(x)sum_{i=1}^{lfloorfrac{n}{d} floor}sum_{j=1}^{lfloorfrac{m}{d} floor}ij[x|gcd(i,j)])

对于判断([x|gcd(i,j)])也要消掉:

(Ans=sum_{d=1}^{min(n,m)}dsum_{x=1}^{min(lfloorfrac{n}{d} floor,lfloorfrac{m}{d} floor)}mu(x)sum_{xu=1}^{lfloorfrac{n}{d} floor}sum_{xv=1}^{lfloorfrac{m}{d} floor}x^2uv)

最后要处理的式子:

(Ans=sum_{d=1}^{min(n,m)}dsum_{x=1}^{min(lfloorfrac{n}{d} floor,lfloorfrac{m}{d} floor)}x^2mu(x)(sum_{u=1}^{lfloorfrac{n}{dx} floor}u)(sum_{v=1}^{lfloorfrac{m}{dx} floor}v))

直接分块,另((sum_{u=1}^{lfloorfrac{n}{dx} floor}u)(sum_{v=1}^{lfloorfrac{m}{dx} floor}v))相同

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL p=20101009;
const int maxn=1e7+10;
inline int Read(){
    LL 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 n,m;
LL ans;
int mu[maxn],prime[maxn];
LL sum[maxn];
bool visit[maxn];
inline void F_phi(LL max_n){
    mu[1]=1;
    int tot=0;
    for(int i=2;i<=max_n;++i){
        if(!visit[i]){
            prime[++tot]=i,
            mu[i]=-1;
        }
        for(int j=1;j<=tot&&i*prime[j]<=max_n;++j){
            visit[i*prime[j]]=true;
            if(i%prime[j]==0)
                break;
            else
                mu[i*prime[j]]=-mu[i];
        }
    }
    for(int i=1;i<=max_n;++i)
        sum[i]=(sum[i-1]+(LL)mu[i]*i%p*i%p)%p;
}
int main(){
    scanf("%d%d",&n,&m);
    int N=min(n,m);
    F_phi(N);
    for(int d=1;d<=N;++d){
        int maxx=n/d,maxy=m/d;
        int x=min(maxx,maxy);
        LL num=0;
        for(int l=1,r;l<=x;l=r+1){
            r=min(maxx/(maxx/l),maxy/(maxy/l));
            num=(num+
            ((sum[r]-sum[l-1]+p)%p)*
            ((((1ll+maxx/l)%p)*1ll*(maxx/l)/2%p)%p)%p*
            ((((1ll+maxy/l)%p)*1ll*(maxy/l)/2%p)%p)%p)%p;
        }
        ans=(ans+(num*1ll*d)%p)%p;
    }
    printf("%lld",ans);
    return 0;
}/*
1000000 1000000
9002207
*/

以上是关于P1829 [国家集训队]Crash的数字表格 / JZPTAB的主要内容,如果未能解决你的问题,请参考以下文章

P1829 [国家集训队]Crash的数字表格 / JZPTAB

[国家集训队]Crash的数字表格 / JZPTAB

题解[国家集训队]Crash的数字表格 / JZPTAB

「luogu1829」 [国家集训队]Crash的数字表格

[国家集训队]Crash的数字表格 / JZPTAB

bzoj2154 Crash的数字表格