Given two numbers a and b, and a number k which is odd. The task is to find all the numbers between a and b (both inclusive) having exactly k divisors.
Input : a = 2, b = 49, k = 3 Output: 4 // Between 2 and 49 there are four numbers // with three divisors // 4 (Divisors 1, 2, 4), 9 (Divisors 1, 3, 9), // 25 (Divisors 1, 5, 25} and 49 (1, 7 and 49) Input : a = 1, b = 100, k = 9 Output: 2 // between 1 and 100 there are 36 (1, 2, 3, 4, 6, 9, 12, 18, 36) // and 100 (1, 2, 4, 5, 10, 20, 25, 50, 100) having exactly 9 // divisors
This problem has simple solution, here we are given that k is odd and we know that only perfect square numbers have odd number of divisors , so we just need to check all perfect square numbers between a and b, and calculate divisors of only those perfect square numbers.
This problem can be solved more efficiently. Please refer method 2 of below post for an efficient solution.
This article is contributed by Shashank Mishra ( Gullu ). 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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 a number has an odd count of odd divisors and even count of even divisors
- Program to find count of numbers having odd number of divisors in given range
- Check if count of even divisors of N is equal to count of odd divisors
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Maximum possible prime divisors that can exist in numbers having exactly N divisors
- Count numbers from given range having odd digits at odd places and even digits at even places
- Find numbers with n-divisors in a given range
- Find sum of divisors of all the divisors of a natural number
- Count of elements having odd number of divisors in index range [L, R] for Q queries
- Find the number of divisors of all numbers in the range [1, n]
- Divisors of n-square that are not divisors of n
- Minimum value exceeding X whose count of divisors has different parity with count of divisors of X
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Sum of product of proper divisors of all Numbers lying in range [L, R]
- Count of nodes having odd divisors in the given subtree for Q queries
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Average of odd numbers till a given odd number
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Querying maximum number of divisors that a number in a given range has
Improved By : nitin mittal