VOOZH about

URL: https://www.geeksforgeeks.org/dsa/count-integers-in-a-range-which-are-divisible-by-their-euler-totient-value/

⇱ Count integers in a range which are divisible by their euler totient value - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Count integers in a range which are divisible by their euler totient value

Last Updated : 11 Jul, 2025

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:
(2) = 2 => 2 % (2) = 0 
(3) = 2 => 3 % (3) = 1 
Hence 2 satisfies the condition.
Input: L = 12, R = 21 
Output:
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:
 


Output: 
3

 
Comment
Article Tags:
Article Tags: