crash的数字表格
所谓莫比乌斯反演,就是把好看的式子变得越来越猥琐(题外话)
开始变形:
\[\sum\limits_{i=1}^n\sum\limits_{j=1}^mlca(i,j)
\]
\[=\sum\limits_{i=1}^n\sum\limits_{j=1}^m\frac{ij}{\gcd(i,j)}
\]
\[=\sum\limits_{d=1}^n\frac1d\sum\limits_{i=1}^{\left[\frac nd\right]}\sum\limits_{j=1}^{\left[\frac md\right]}ijd^2*[\gcd(i,j)=1]
\]
\[=\sum\limits_{d=1}^nd\sum\limits_{i=1}^{\left[\frac nd\right]}\sum\limits_{j=1}^{\left[\frac md\right]}ij\sum\limits_{k|\gcd(i,j)}\mu(k)
\]
\[=\sum\limits_{d=1}^nd\sum\limits_{k=1}^{\left[\frac nd\right]}\mu(k)k^2\sum\limits_{i=1}^{\left[\frac {n}{dk}\right]}\sum\limits_{j=1}^{\left[\frac {m}{dk}\right]}ij
\]
\[=\sum\limits_{d=1}^nd\sum\limits_{k=1}^{\left[\frac nd\right]}\mu(k)k^2\frac14\left[\frac {n}{dk}\right]\left(\left[\frac {n}{dk}\right]+1\right)\left[\frac {m}{dk}\right]\left(\left[\frac {m}{dk}\right]+1\right)
\]
这时使出我们的必杀技:令\(t=dk\)
\[\frac14\sum\limits_{t=1}^n\left[\frac {n}{t}\right]\left(\left[\frac {n}{t}\right]+1\right)\left[\frac {m}{t}\right]\left(\left[\frac {m}{t}\right]+1\right)\sum\limits_{d|t}\mu(d)d^2\frac td
\]
\[=\frac14\sum\limits_{t=1}^n\left[\frac {n}{t}\right]\left(\left[\frac {n}{t}\right]+1\right)\left[\frac {m}{t}\right]\left(\left[\frac {m}{t}\right]+1\right)\sum\limits_{d|t}\mu(d)dt
\]
对于每一个\(t\),\(\sum\limits_{d|t}\mu(d)dt\)可以预处理,其余分块即可。
附上代码,放心食用:
#include<bits/stdc++.h>
#define int long long
const int maxn=1e7;
const int mod=20101009;
int mu[maxn+10],h[maxn+10],pri[maxn/100],tot;
int n,m;
inline void init(){
mu[1]=1;
for(int i=2;i<=n;i++){
if(!h[i])mu[i]=-1,pri[++tot]=i;
for(int j=1;j<=tot&&pri[j]*i<=n;j++){
h[pri[j]*i]=1;
if(i%pri[j]==0)break;
mu[pri[j]*i]=-mu[i];
}
}
memset(h,0,sizeof(h));
for(int i=1;i<=n;i++)
if(mu[i]!=0)
for(int j=1;j<=n/i;j++)
h[i*j]=(h[i*j]+mu[i]*i)%mod;
for(int i=1;i<=n;i++)
h[i]=(i*h[i]+h[i-1])%mod;
}
signed main(){
scanf("%lld%lld",&n,&m);
if(n>m)std::swap(n,m);
init();
int ans=0;
for(int l=1,r;l<=n;l=r+1){
r=std::min(n/(n/l),m/(m/l));
ans=(ans+((((n/l)*(n/l+1)/2)%mod)*(((m/l)*(m/l+1)/2)%mod)%mod*(h[r]-h[l-1])%mod))%mod;
}
printf("%lld\n",(ans%mod+mod)%mod);
return 0;
}
深深地感到自己的弱小。