Euler function play table

 1 #include<bits/stdc++.h>
 2 #define ll long long 
 3 #define scan(i) scanf("%d",&i)
 4 #define scand(i) scanf("%lf",&i)
 5 #define scanl(i) scanf("%lld",&i)
 6 #define f(i,a,b) for(int i=a;i<=b;i++) 
 7 #define pb(i) push_back(i)
 8 #define ppb pop_back()
 9 #define pf printf
10 #define dbg(args...) cout<<#args<<" : "<<args<<endl;
11 using namespace std;
12 #define Max 100001
13 int Euler [Max];
 14  void the init () {
 15       Euler [ . 1 ] = . 1 ;
 16       for ( int I = 2 ; I <Max; I ++ )
 . 17         Euler [I] = I;
 18 is       for ( int I = 2 ; I <Max; I ++ )
 . 19          IF (Euler [I] == I)
 20 is             for ( int J = I; J <Max; J + = I)
 21 is                Euler [J] = Euler [J] / I * (I- . 1 ); // first division is performed to prevent the overflow of the intermediate data 
22  }
23  // general formula counted 
24  int the Euler ( int n-) { // return Euler (n-) 
25      int RES = n-, A = n-;
 26 is      for ( int I = 2 ; I * I <= A; I ++ ) {
 27          IF (a% I == 0 ) {
 28              RES = RES / I * (I- . 1 ); // first division is performed to prevent the overflow of the intermediate data 
29              the while (I% a == 0 ) a / = I;
 30          }
 31 is      }
 32      IF (A> . 1 ) RES = RES / A * (A- . 1);
33     return res;
34 }

When called, the first use init ();

Then i corresponds Euler function value is stored in the Euler [i] a;

Where 0 <i <Max;

Guess you like

Origin www.cnblogs.com/St-Lovaer/p/11404925.html