传送门
反演一波
枚举k,l
发现n/t 总共有根号n个取值, 每算一次前缀和是根号n的
可以证明时间复杂度是n^3/4, mu用杜教筛
#include<bits/stdc++.h>
#define N 2000050
#define Mod 1000000007
#define LL long long
#define M 50050
using namespace std;
int prim[N],mu[N],isp[N],tot;
int n; LL val[N];
map<int,int> Mu;
void prework(){
mu[1] = 1;
for(int i=2;i<=N-50;i++){
if(!isp[i]) prim[++tot] = i, mu[i] = -1;
for(int j=1;j<=tot;j++){
if(i*prim[j] > N - 50) break;
isp[i*prim[j]] = 1;
if(i%prim[j]==0) break;
mu[i*prim[j]] = -mu[i];
}
}
for(int i=2;i<=N-50;i++) mu[i] += mu[i-1];
for(int i=1;i<=M-50;i++){
for(int l=1,r;l<=i;l=r+1){
int v = i/l; r = i/v;
val[i] += (LL)(r-l+1) * (LL)v % Mod;
val[i] %= Mod;
}
}
}
LL getval(int x){
if(x<=M-50) return val[x];
LL ans = 0;
for(int l=1,r;l<=x;l=r+1){
int v = x/l; r = x/v;
ans += (LL)(r-l+1) * (LL)v % Mod;
ans %= Mod;
} return ans;
}
int getf(int x){
if(x<=N) return mu[x];
if(Mu[x]) return Mu[x];
int ans = 1;
for(int l=2,r;l<=x;l=r+1){
int v = x/l; r = x/v;
ans -= (r-l+1) * getf(v);
} return Mu[x] = ans;
}
int main(){
prework();
scanf("%d",&n); LL ans = 0;
for(int l=1,r;l<=n;l=r+1){
int v = n/l; r = n/v;
LL tmp = getval(v); tmp = (tmp * tmp) % Mod;
ans += (LL)(getf(r) - getf(l-1)) * tmp % Mod;
ans = (ans % Mod + Mod) % Mod;
} printf("%lld",ans); return 0;
}