莫比乌斯函数

const int maxn=1000000+5;
bool check[maxn];
int prime[maxn],mu[maxn];
void Moblus(int n){
    memset(check,0,sizeof(check));
    mu[1]=1;
    int tot=0;
    for(int i=2;i<=n;i++){
        if(!check[i]){
            prime[tot++]=i;
            mu[i]=-1;
        }
        for(int j=0;j<tot;j++){
            if(i*prime[j]>n) break;
            check[i*prime[j]]=true;
            if(i%prime[j]==0){
                mu[i*prime[j]]=0;
                break;
            }else mu[i*prime[j]]=-mu[i];
        }
    }
}
原文地址:https://www.cnblogs.com/033000-/p/10088745.html