Introduction to Euler functions --Excerpts from Baidu Encyclopedia
Note The following three special properties
Programmatic Implementation
By using the relation of Euler function and its different mass factor, the Euler function value of all numbers in a certain range is calculated by Sieve method.
Solve the Euler function directly
#include <cstdio>
int Euler (int n) {//return Euler (n)
int res=n,a=n;
for (int i=2;i*i<=a;i++) {////Small to large try N's mass factor
if (a%i==0) {//If I is the mass factor of n
res=res/i* (i-1); a 1/i comes out, The first Division is to prevent the overflow of intermediate data while
(a%i==0) a/=i;//Euler functions are only counted as a mass factor
}
if (a>1) res=res/a* (A-1); If the last remaining factor return
res;
}
int main () {
int x;
scanf ("%d", &x);
printf ("%d", Euler (x));
return 0;
}
//screening method play Euler function table #include <cstdio> #define MAX 1000001 int Euler[max];
void Init () {euler[1]=1;
for (int i=2;i<max;i++) euler[i]=i; for (int i=2;i<max;i++) if (euler[i]==i)//If I is prime number for (int j=i;j<max;j+=i) euler[j
]=euler[j]/i* (i-1), or to mention a 1/i, First division is to prevent the overflow of intermediate data return;
int main () {Init ();
for (int i=1;i<=100;i++) printf ("%d\n", Euler[i]);
return 0; }