题意:求$sum_{i=1}^{n}sum_{j=1}^{m}lcm(i,j)$。
开始开心(自闭)化简:
$sum_{i=1}^{n}sum_{j=1}^{m}lcm(i,j)$
=$sum_{d=1}^{n}sum_{i=1}^{n}sum_{j=1}^{m}frac{ij}{d}[gcd(i,j)==d]$
=$sum_{d=1}^{n}sum_{i=1}^{lfloor frac{n}{d} floor}sum_{j=1}^{lfloor frac{m}{d} floor}ijd[gcd(i,j)==1]$
=$sum_{d=1}^{n}dsum_{i=1}^{lfloor frac{n}{d} floor}mu(i)i^2S({lfloor frac{n}{id} floor})S({lfloor frac{m}{id} floor}),S(n)=(n+1)*n/2$
=$sum_{T=1}^{n}S({lfloor frac{n}{T} floor})S({lfloor frac{m}{T} floor})sum_{d|T}d(frac{T}{d})^2mu(frac{T}{d})$
=$sum_{T=1}^{n}S({lfloor frac{n}{T} floor})S({lfloor frac{m}{T} floor})Tsum_{d|T}(frac{T}{d})mu(frac{T}{d})$
令$F(T)=Tsum_{d|T}(frac{T}{d})mu(frac{T}{d})$
只需要预处理F的前缀和,前面整除分块问题就解决了。
$F(1)=1,F(p^c)=mu(1)*1+mu(p)*p=1-p$
可以知道F是一个积性函数,对T进行质因数分解,即可求得F(T),可以在筛质数的时候进行求解,具体看代码。
#include <bits/stdc++.h> #define ll long long using namespace std; const int N=1e7+5; const int MD=20101009; bool p[N]; int pri[N],f[N],tot; void init() { f[1]=1; for(int i=2;i<N;i++) { if(!p[i]) pri[tot++]=i,f[i]=1-i+MD; for(int j=0;j<tot&&i*pri[j]<N;j++) { p[i*pri[j]]=true; if(i%pri[j]==0) { f[i*pri[j]]=f[i]; break; } else f[i*pri[j]]=1LL*f[i]*f[pri[j]]%MD; } } for(int i=1;i<N;i++) f[i]=1LL*f[i]*i%MD; for(int i=1;i<N;i++) f[i]=(f[i]+f[i-1])%MD; } int cal(int x) { return 1LL*x*(x+1)/2%MD; } int main() { init(); int n,m; scanf("%d%d",&n,&m); if(n>m) swap(n,m); int ans=0; for(int l=1,r;l<=n;l=r+1) { r=min(n/(n/l),m/(m/l)); ans=(ans+1LL*(f[r]-f[l-1]+MD)*cal(n/l)%MD*cal(m/l)%MD)%MD; } printf("%d ",ans); return 0; }