Euler screen play table

. 1  const  int N = 1E7;
 2  int Phi [N + 10 ], Prime [N + 10 ], TOT, ANS;
 . 3  BOOL Mark [N + 10 ];   
 . 4  void getphi () {    
 . 5     int I, J;    
 . 6     Phi [ . 1 ] = . 1 ;    
 . 7     for (i = 2 ; i <= N; i ++ ) {    
 . 8         iF (! {Mark [i])    
 . 9               prime [++ TOT] = i; // number of sieve prime time will first determines whether i is Prime number.    
10               Phi [I] = I-1 ; // if i is a prime number Phi [i] = i-1     
. 11               }    
 12 is         for (J = 1 ; J <= TOT; J ++ ) {    
 13 is            IF (i * Prime [J]> N)   BREAK ;    
 14            Mark [i * prime [j]] = . 1 ; // determine i * prime [j] is not a prime number     
15            iF (i% prime [j] == 0 ) { // Next we will look prime [j] of whether i submultiple     
16               Phi [I * Prime [J]] = Phi [I] * Prime [J]; BREAK ;    
 . 17            }    
 18 is            the else Phi [I * Prime [J]] = Phi [I] * (Prime [J] - 1 );// In fact, here prime [j] -1 is phi [prime [j]], using the product of the Euler function     
19         }    
 20     }    
 21  } 
 22  // When invoked, given getphi (); to, Phi [ i] is a false note is a prime number, otherwise it is a composite number

Each call is given getphi ();

Playing table filled phi between n 1 ~ [];

Guess you like

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