欧拉筛 线性筛 素数+莫比乌斯的mu[]

https://blog.csdn.net/qq_39763472/article/details/82428602

模板来自 https://blog.csdn.net/Avalon_cc/article/details/81663214

bool isP[N];
int P[N], ind;
void Euler() {
    mem(isP,1);
    mu[1]=1; ind=0;
    for(int i=2;i<N;i++) {
        if(isP[i]) P[ind++]=i, mu[i]=-1;
        for(int j=0;j<ind;j++) {
            if(i*P[j]>N) break;
            isP[i*P[j]]=0;
            if(i%P[j]==0) {
                mu[i*P[j]]=0; break;
            } else mu[i*P[j]]=-mu[i];
        }
    }
} // 欧拉筛
View Code

猜你喜欢

转载自www.cnblogs.com/zquzjx/p/10383663.html