从别人博客里摘录过来改写的:https://quartergeek.com/sieve-prime-in-linear-time/
typedef long long LL;
#define mn 100000+5
LL ph[mn];
bool vis[mn];
int primes, prime[mn];
void Init()
{
ph[1] = 1;
primes=0;
for (LL i = 2; i < mn; ++i)
{
if (!vis[i])
{
prime[primes++] = i;
ph[i] = i-1;
}
for (LL j = 0; j < primes && i*prime[j] < mn; ++j)
{
vis[i*prime[j]] = true;
if (i % prime[j])
ph[i*prime[j]] = ph[i]*(prime[j]-1);
else
{
ph[i*prime[j]] = ph[i]*prime[j];
break;
}
}
}
}
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 60000+5;
bool vis[maxn];
int prime[maxn],primes,mu[maxn];
void init_mu()
{
memset(vis,0,sizeof(vis));
mu[1]=1;
primes=0;
for(int i=2; i<maxn; i++)
{
if(!vis[i]){
prime[primes++]=i;
mu[i]=-1;
}
for(int j=0; j<primes&&i*prime[j]<maxn; j++)
{
vis[i*prime[j]]=1;
if(i%prime[j]) mu[i*prime[j]]=-mu[i];
else { mu[i*prime[j]]=0;break;}
}
}
}