Given two integers A and B. The task is to count how many numbers in the interval [ A, B ] have an odd number of divisors.
Input : A = 1, B = 10 Output : 3 Input : A = 5, B = 15 Output : 1
Naive Approach :
The simple approach would be to iterate through all the numbers between range [A, B] and check if their number of divisors is odd.
Below is the implementation of the above idea :
Please refer Number of elements with odd factors in given range for a better approach.
- Find the number of divisors of all numbers in the range [1, n]
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Find numbers with K odd divisors in a given range
- Find numbers with n-divisors in a given range
- Count elements in the given range which have maximum number of divisors
- Count the numbers < N which have equal number of divisors as K
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Count total divisors of A or B in a given range
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Find sum of divisors of all the divisors of a natural number
- Find kth smallest number in range [1, n] when all the odd numbers are deleted
- Querying maximum number of divisors that a number in a given range has
- C Program to Check if count of divisors is even or odd
- Java Program to Check if count of divisors is even or odd
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.