![]() |
VOOZH | about |
Given 2 integers L and R, the task is to find out the number of integers in the range [L, R] such that they are completely divisible by their Euler totient value.
Examples:
Input: L = 2, R = 3
Output: 1
(2) = 2 => 2 % (2) = 0
(3) = 2 => 3 % (3) = 1
Hence 2 satisfies the condition.
Input: L = 12, R = 21
Output: 3
Only 12, 16 and 18 satisfy the condition.
Approach: We know that the euler totient function of a number is given as follows:
Rearranging the terms, we get:
If we take a close look at the RHS, we observe that only 2 and 3 are the primes that satisfy n % = 0. This is because for primes p1 = 2 and p2 = 3, p1 - 1 = 1 and p2 - 1 = 2. Hence, only numbers of the form 2p3q where p >= 1 and q >= 0 need to be counted while lying in the range [L, R].
Below is the implementation of the above approach:
3