Question:
For a and B
F [a] + F [A + 1] +... f [B]
F is the corresponding Euler's function value.
Solution:
Linear screening method, because Euler's function is a product function
Use the screening method to calculate the Euler's function value
If P has I, then (p * I) = (p-1) * Then (I)
If p | I, then (p * I) = p * Then (I)
Calculate the Euler's function value of all numbers in 1 to 10 ^ 6 based on the two formulas above by screening.
Then use the ANS array to represent
Ans [I] = f [1] + F [2] +... f [ANS]
When A and B are input, the result is
Ans [B]-ans [a] + F [A]
# Include <iostream> # include <algorithm> # include <cstdio> using namespace STD; # define Max 1000100 long f [Max]; // The Void Init () function value () // sieve out the Euler's function values of all numbers within max {memset (F, 0, sizeof (f); F [1] = 1; for (long I = 2; I <Max; I ++) {If (F [I] = 0) // I is a prime number {f [I] = I-1; For (long j = 1; J * I <Max; j ++) // If P has I, then (p * I) = (p-1) * Then (I) // if p | I, percentile (p * I) = p * percentile (I) // P is a prime number, And I is a multiple {If (J % I = 0) {f [I * j] = I * f [J];} else {f [I * j] = (I-1) * f [J] ;}}} long long ans [Max]; int Ma In () {Init (); long a, B; ans [1] = f [1]; for (long I = 2; I <Max; I ++) {ans [I] = ans [I-1] + F [I];} while (~ Scanf ("% d", & A, & B) {printf ("% LLD \ n ", ans [B]-ans [a] + F [a]);} return 0 ;}