题意
计算 (sum_{i=1}^{n}sum_{j=1}^{m}lcm(i,j))
题解
[egin{aligned}Ans=sum_{i=1}^{N}sum_{j=1}^{M}lcm(i,j)&=sum_{i=1}^{N}sum_{j=1}^{M}frac{ij}{gcd(i,j)}=sum_{d=1}^{N}sum_{i=1}^{N}sum_{j=1}^{M}[gcd(i,j)=d]frac{ij}{d}\&=sum_{d=1}^{N}frac{1}{d}sum_{i=1}^{N}sum_{j=1}^{M}[gcd(i,j)=d]ij\end{aligned}
]
设:
[f(d)=sum_{i=1}^{N}sum_{j=1}^{M}[gcd(i,j)=d]ij\F(n)=sum_{n|d}f(d)=sum_{n|i}^{N}sum_{n|j}^{M}ij=sum_{i=1}^{frac{N}{n}}sum_{j=1}^{frac{M}{n}}incdot jn=n^2sum_{i=1}^{frac{N}{n}}sum_{j=1}^{frac{M}{n}}ij
]
然后反演 (f(n)):
[egin{aligned}f(n)&=sum_{n|d}mu(frac{d}{n})F(d)=sum_{n|d}mu(frac{d}{n})d^2sum_{i=1}^{frac{N}{d}}sum_{j=1}^{frac{M}{d}}ij=sum_{t=1}^{frac{N}{n}}mu(t)n^2t^2sum_{i=1}^{frac{N}{nt}}sum_{j=1}^{frac{M}{nt}}ij\&=n^2sum_{t=1}^{frac{N}{n}}mu(t)t^2sum_{i=1}^{frac{N}{nt}}isum_{j=1}^{frac{M}{nt}}jend{aligned}
]
然后代回去求 (Ans):
[egin{aligned}Ans=sum_{n=1}^{N}frac{1}{n}f(n)&=sum_{n=1}^{N}nsum_{t=1}^{frac{N}{n}}mu(t)t^2sum_{i=1}^{frac{N}{nt}}isum_{j=1}^{frac{M}{nt}}j=sum_{T=1}^{N}Tsum_{t|T}mu(t)tsum_{i=1}^{frac{N}{T}}isum_{j=1}^{frac{M}{T}}jend{aligned}
]
关于 (f(T)=sum_{t|T}mu(t)t),可以证明它是一个积性函数:
[T(mu*id_{-1})(T)=Tsum_{t|T}mu(t)frac{t}{T}=sum_{t|T}mu(t)t
]
若 (n,p) 互质,那么满足积性函数要求, (f(np)=f(n)f(p))。
若 (p|n),那么 (f(np)=f(n)),因为 (np) 比 (n) 多的因数必然有多个因子 (p),所以这部分因数的 (mu) 值为 (0)。
代码
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
typedef long long LL;
const int N=1e7+10;
const int mod=20101009;
int n,m,vis[N],prime[N],cnt;
LL sum[N],f[N];
void init(int n){
f[1]=1;
for(int i=2;i<=n;i++){
if(!vis[i]) {prime[++cnt]=i;f[i]=(1-i+mod)%mod;}
for(int j=1;1ll*i*prime[j]<=n;j++){
vis[i*prime[j]]=1;
if(i%prime[j]==0) {f[i*prime[j]]=f[i];break;}
f[i*prime[j]]=f[i]*f[prime[j]]%mod;
}
}
for(int i=1;i<=n;i++) sum[i]=(f[i]*i+sum[i-1])%mod;
}
int main(){
init(1e7);
scanf("%d%d",&n,&m);
if(n>m) swap(n,m);
LL ans=0;
for(int l=1,r;l<=n;l=r+1){
r=min(n/(n/l),m/(m/l));
LL temp1=1ll*(n/l+1)*(n/l)/2%mod;
LL temp2=1ll*(m/l+1)*(m/l)/2%mod;
ans=(ans+(sum[r]-sum[l-1]+mod)%mod*temp1%mod*temp2%mod)%mod;
}
printf("%lld
",ans);
return 0;
}