题目链接

https://lydsy.com/JudgeOnline/problem.php?id=4176

题解

莫比乌斯反演得到
k=1nμ(k)i=1n/kσ0(i)i=1n/kσ0(i) \sum_{k=1}^{n} \mu(k)\sum_{i=1}^{\lfloor n/k\rfloor}\sigma_0(i)\sum_{i=1}^{\lfloor n/k\rfloor}\sigma_0(i)

f(k)=i=1kσ0(i)=i=1kdk1=d=1kkd f(k)=\sum_{i=1}^k \sigma_{0}(i)=\sum_{i=1}^k \sum_{d|k}1=\sum_{d=1}^k \lfloor\frac{k}{d}\rfloor
因此可以整除分块求ff

代码

#include <map>
#include <cstdio>
#include <algorithm>
 
int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
         f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}
 
const int maxn=1000000;
const int mod=1000000007;
 
int p[maxn+10],prime[maxn+10],cnt,mu[maxn+10];
 
int getprime()
{
  p[1]=mu[1]=1;
  for(int i=2; i<=maxn; ++i)
    {
      if(!p[i])
        {
          prime[++cnt]=i;
          mu[i]=mod-1;
        }
      for(int j=1; (j<=cnt)&&(i*prime[j]<=maxn); ++j)
        {
          int x=i*prime[j];
          p[x]=1;
          if(i%prime[j]==0)
            {
              mu[x]=0;
              break;
            }
          mu[x]=mod-mu[i];
        }
    }
  for(int i=2; i<=maxn; ++i)
    {
      mu[i]+=mu[i-1];
      if(mu[i]>=mod)
        {
          mu[i]-=mod;
        }
    }
  return 0;
}
 
std::map<int,int> mp;
 
int getsum(int n)
{
  if(n<=maxn)
    {
      return mu[n];
    }
  if(mp.count(n))
    {
      return mp[n];
    }
  int ans=1;
  for(int l=2,r; l<=n; l=r+1)
    {
      r=n/(n/l);
      ans-=1ll*getsum(n/l)*(r-l+1)%mod;
      if(ans<0)
        {
          ans+=mod;
        }
    }
  return mp[n]=ans;
}
 
int getd(int n)
{
  int ans=0;
  for(int l=1,r; l<=n; l=r+1)
    {
      r=n/(n/l);
      ans=(ans+1ll*(r-l+1)*(n/l))%mod;
    }
  return ans;
}
 
int sqr(int x)
{
  return 1ll*x*x%mod;
}
 
int n;
 
int main()
{
  getprime();
  n=read();
  int ans=0;
  for(int l=1,r; l<=n; l=r+1)
    {
      r=n/(n/l);
      ans=(ans+1ll*(getsum(r)-getsum(l-1)+mod)*sqr(getd(n/l)))%mod;
    }
  printf("%d\n",ans);
  return 0;
}