typedef long long ll; 
bool check[N];
int mu[N],pri[N],tot;
ll phi[N];
void init(int lim){
    check[1]=1,phi[1]=0;mu[1]=1;
    for(int i=2;i<=lim;i++){
        if(!check[i]){
            pri[++tot]=i;phi[i]=i-1;mu[i]=-1;
        }
        for(int j=1;j<=tot&&i*pri[j]<=lim;j++){
            check[i*pri[j]]=1;
            if(i%pri[j]==0){
                phi[i*pri[j]]=phi[i]*pri[j];
                mu[i*pri[j]]=0;
                break;
            }
            else{
                phi[i*pri[j]]=phi[i]*(pri[j]-1);
                mu[i*pri[j]]=-mu[i];
            }
        }
    }
}

 

相关文章:

  • 2018-10-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2021-05-26
  • 2018-11-26
猜你喜欢
  • 2022-12-23
  • 2021-12-01
  • 2020-10-07
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
相关资源
相似解决方案