VOOZH about

URL: https://www.geeksforgeeks.org/dsa/count-of-integers-up-to-n-which-are-non-divisors-and-non-coprime-with-n/

⇱ Count of integers up to N which are non divisors and non coprime with N - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Count of integers up to N which are non divisors and non coprime with N

Last Updated : 15 Jul, 2025

Given an integer N, the task is to find the count of all possible integers less than N satisfying the following properties:

  • The number is not coprime with N i.e their GCD is greater than 1.
  • The number is not a divisor of N.


Examples:

Input: N = 10 
Output:
Explanation: 
All possible integers which are less than 10 and are neither divisors nor coprime with 10, are {4, 6, 8}. 
Therefore, the required count is 3.
Input: N = 42 
Output: 23


Approach: 
Follow the steps below to solve the problem:

Total count = N - Euler's totient(N) - Divisor count(N)


Below is the implementation of the above approach:


Output: 
23

Time Complexity: O(N*log(log(N))) 
Auxiliary Space: O(N)
 

Comment