做莫比乌斯的题所需要的代码:

#include"bits/stdc++.h"
#define C(n,m) ((long long)fac[(n)]*inv[(m)]%MOD*inv[(n)-(m)]%MOD)
using namespace std;
const int maxn=3e5+5;
const int MOD=1e9+7;
char mu[maxn];
int sum[maxn];
vector<int>prime;
bool vis[maxn];
int fac[maxn]={1,1},inv[maxn]={1,1};
long long ksm(long long a,long long b,long long mod)
{
    long long res=1,base=a;
    while(b)
    {
        if(b&1)res=(res*base)%mod;
        base=(base*base)%mod;
        b>>=1;
    }
    return res;
}

void Init(int NN)
{
    memset(vis,1,sizeof(vis));
    mu[1]=1;
    for(int i=2;i<=NN;i++)
    {
        if(vis[i])
        {
            prime.push_back(i);
            mu[i]=-1;
        }
        for(int j=0;j<prime.size()&&i*prime[j]<=NN;j++)
        {
            vis[i*prime[j]]=0;
            if(i%prime[j]==0)
            {
                mu[i*prime[j]]=0;
                break;
            }
            else mu[i*prime[j]]=-mu[i];
        }
        fac[i]=(long long)fac[i-1]*i%MOD;
        inv[i]=ksm(fac[i],MOD-2,MOD);
    }
}
long long F(int d,int n,int m)//F(d)
{
    return (long long)(n/d)*(m/d);
}
long long f(int x,int n,int m)//f(d)
{
    if(n>m)swap(n,m);
    long long res=0;
    int j;
    for(int i=1,d=x;i<=n;i=j+1)//错误地方:d每次的值和i不一样
    {
        j=min(n/(n/i),m/(m/i));//要两个里面最小的
        res+=(long long)(sum[j]-sum[i-1])*F(d,n,m);
        d+=x*(j-i+1);
    }
    return res;
}