1. A god Ben Blog learned three times the Euler function Φ--deadfish7
2. I'm going to do some supplemental O (* ̄▽ ̄*) o
$φ (1) =1$;
There are two forms of the formula, one with too many divisions, which may actually be slower. General
For any $n$>1,1~ $n $ in the sum of $n$ coprime equals $n*φ (n)/2$.
is an integrable function.
$sigma (d|n) φ (d) =n$.
Code implementation
1 °: simple qualitative factor decomposition by the way to find out
void Init_phi () { int ans=n; for (int i=2; i<=sqrt (n); i++) { if(n%i==0) { ans=ans/i* (-1); while (n%i==0) n/=i; } if (n>1) ans=ans/n* (n1);} }
Applies to a single query, but the efficiency is a bit low, $O (sqrt (n)) $, boingonium.
2 °: The number of linear sieve, by the way the Euler function is also complete. (for recursion, continuous 1~n)
On the linear sieve board a slight modification can be, the complexity of $o (n) $.
voidInit_phi () {phi[1]=1; for(intI=2; i<=lim;i++) { if(v[i]==0) {prime[++m]=i; V[i]=i; Phi[i]=i-1; } for(intj=1; j<=m;j++) { if(prime[j]>v[i]| | prime[j]>lim/i) Break; V[i*prime[j]]=Prime[j]; Phi[i*prime[j]]=phi[i]* (I%prime[j]? prime[j]-1:p rime[j]); } }}
Example Honor Guard
On Euler function by cellur925