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.
Input: L = 2, R = 3
(2) = 2 => 2 % (2) = 0
(3) = 2 => 3 % (3) = 1
Hence 2 satisfies the condition.
Input: L = 12, R = 21
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:
- Euler's Totient Function
- Euler's Totient function for all numbers smaller than or equal to n
- Optimized Euler Totient Function for Multiple Evaluations
- Ways to form an array having integers in given range such that total sum is divisible by 2
- Count of m digit integers that are divisible by an integer n
- Count of integers of the form (2^x * 3^y) in the range [L, R]
- Count numbers in range 1 to N which are divisible by X but not by Y
- Count the numbers divisible by 'M' in a given range
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count numbers in range L-R that are divisible by all of its non-zero digits
- Count of Numbers in a Range divisible by m and having digit d in even positions
- Count numbers in a range that are divisible by all array elements
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Minimum elements to be added in a range so that count of elements is divisible by K
- Count the number of pairs (i, j) such that either arr[i] is divisible by arr[j] or arr[j] is divisible by arr[i]
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.