Definition of Euler function φ(n): the number of positive integers smaller than n that are relatively prime to n.
General formula: φ(n)=n*((p1-1)/p1)*((p2-1)/p2)…((pn-1)/pn) Note: p is the prime factor of
n.
That is, every p one cannot be taken (that is, the multiple of p cannot be taken)
and n is a prime number is φ(n)=n-1
, so the Euler function of 1~n can be linearly deduced
scanf("%d",&n);
for(int i=2;i<=n;i++){
if(!ispri[i]){
prime[++tot]=i;
phi[i]=i-1;
}
for(int j=1;j<=tot && prime[j]*i<=n;j++){
ispri[i*prime[j]]=1;
if(i%prime[j]==0){
phi[i*prime[j]]=phi[i]*prime[j];
break;
}else
phi[i*prime[j]]=phi[i]*phi[prime[j]];
}
}