HDU 2824 the Euler function
Euler's function: θ (n) is the number of Integers of All integers less than N, and N. N is a positive integer.
Euler proves the following formula:
If the standard prime factor decomposition formula of N is P1 ^ A1 * P2 ^ A2 *...... * PM ^ am, where all PJ (j = ,......, M) are all prime numbers, and they are not equal to each other. Then there is
Phi (n) = N (1-1/P1) (1-1/P2 )...... (1-1/pm)
If n is an odd prime number, Phi (n) = n-1.
Solution: Linear Regression Method
In Program Using the following Euler's function, you can quickly find the Euler's value (A is a qualitative factor of N)
(1) If (N % A = 0 & (n/a) % A = 0), E (n) = E (N/) *;
(2) If (N % A = 0 & (n/a) %! = 0) then there are: E (n) = E (n/a) * (A-1 );
# Include <stdio. h> # include <stdlib. h >__ int64 num [3000024]; int prime [220000]; bool isprime [3000024] = {0}; void Eular () {int COUNT = 0 ;__ int64 K; for (INT I = 2; I <= 3000000; I ++) {If (! Isprime [I]) {Prime [++ count] = I; num [I] = I-1;} For (Int J = 1; j <= count & (k = prime [J] * I) <= 3000000); j ++) {isprime [k] = 1; if (I % prime [J] = 0) {num [k] = num [I] * prime [J];} else num [k] = num [I] * (Prime [J]-1) ;}} int main () {int n, m, I; Eular (); // The results are stored in num [] for (I = 3; I <= 3000000; I ++) num [I] = num [I-1] + num [I]; while (scanf ("% d", & N, & M )! = EOF) printf ("% i64d \ n", num [m]-num [n-1]); Return 0 ;}