点击查看折叠代码块
int prim[Maxn],cnt,mu[Maxn],phi[Maxn];
bool vis[Maxn];
void Get(int n){
mu[1] = phi[1] = 1;
for(int i=2;i<=n;i++)
{
if( !vis[i] ) prim[++cnt] = i,mu[i] = -1,phi[i] = i-1;
for(int j=1;j<=cnt&&i*prim[j]<=n;j++)
{
vis[i*prim[j]] = true;
if( i%prim[j] == 0 )
{
phi[i*prim[j]] = phi[i]*prim[j];
break;
}
mu[i*prim[j]] = -mu[i];
phi[i*prim[j]] = phi[i]*(prim[j]-1);
}
}
}