Given two integers N and K, the task is to count all the numbers < N which have equal number of positive divisors as K.
Input: n = 10, k = 5
2, 3 and 7 are the only numbers < 10 which have 2 divisors (equal to the number of divisors of 5)
Input: n = 500, k = 6
- Compute the number of divisor of each number < N and store the result in an array where arr[i] contains the number of divisors of i.
- Traverse arr, if arr[i] = arr[K] then update count = count + 1.
- Print the value of count in the end.
Below is the implementation of the above approach:
The above solution can be optimized using Sieve technique. Please refer Count number of integers less than or equal to N which has exactly 9 divisors for details.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count number of integers less than or equal to N which has exactly 9 divisors
- Check if count of even divisors of N is equal to count of odd divisors
- Program to find count of numbers having odd number of divisors in given range
- Count pairs of natural numbers with GCD equal to given number
- Count of numbers whose sum of increasing powers of digits is equal to the number itself
- Count of numbers below N whose sum of prime divisors is K
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Count of Numbers in Range where first digit is equal to last digit of the number
- Number of divisors of product of N numbers
- Count all perfect divisors of a number
- Count of Fibonacci divisors of a given number
- Count of the non-prime divisors of a given number
- Find the number of divisors of all numbers in the range [1, n]
- Count all pairs of divisors of a number N whose sum is coprime with N
- Count of square free divisors of a given number
- Count elements in the given range which have maximum number of divisors
- Maximum possible prime divisors that can exist in numbers having exactly N divisors
- Count of elements having odd number of divisors in index range [L, R] for Q queries
- Count numbers whose XOR with N is equal to OR with N
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.