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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if count of even divisors of N is equal to count of odd divisors
- Count elements in the given range which have maximum number of divisors
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Check if a number has an odd count of odd divisors and even count of even divisors
- Minimum value exceeding X whose count of divisors has different parity with count of divisors of X
- Count number of integers less than or equal to N which has exactly 9 divisors
- Maximum possible prime divisors that can exist in numbers having exactly N divisors
- Count sub-arrays which have elements less than or equal to X
- Count divisors of n that have at-least one digit common with n
- Find sum of divisors of all the divisors of a natural number
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Count number of rotated strings which have more number of vowels in the first half than second half
- Count of numbers in range which are divisible by M and have digit D at odd places
- Divisors of n-square that are not divisors of n
- Number of divisors of a given number N which are divisible by K
- Find k numbers which are powers of 2 and have sum N | Set 1
- Count of integers up to N which are non divisors and non coprime with N
- Count pairs in an array which have at least one digit common
- Find the count of M character words which have at least one character repeated
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.