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:
- Count integers in the range [A, B] that are not divisible by C and D
- Queries to count integers in a range [L, R] such that their digit sum is prime and divisible by K
- Euler's Totient Function
- Optimized Euler Totient Function for Multiple Evaluations
- Euler's Totient function for all numbers smaller than or equal to n
- 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 the numbers divisible by 'M' in a given range
- Count numbers in range 1 to N which are divisible by X but not by Y
- Count numbers in range L-R that are divisible by all of its non-zero digits
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count numbers in a range that are divisible by all array elements
- Count of Numbers in a Range divisible by m and having digit d in even positions
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.