Given a number “n”, find its total number of divisors are even or odd.
Input : n = 10 Output : Even Input: n = 100 Output: Odd Input: n = 125 Output: Even
A naive approach would be to find all the divisors and then see if the total number of divisors is even or odd.
Time complexity for such a solution would be O(sqrt(n))
The count of divisor: Even
We can observe that the number of divisors is odd only in case of perfect squares. Hence the best solution would be to check if the given number is perfect square or not. If it\’s a perfect square, then the number of divisors would be odd, else it\’d be even.
The count of divisorof 10 is: Even
Please refer complete article on Check if count of divisors is even or odd for more details!
- Python Program for Common Divisors of Two Numbers
- Python Program to Count set bits in an integer
- Python program to count Even and Odd numbers in a List
- Python program to count words in a sentence
- Python | Program to count duplicates in a list of tuples
- Python Program to Count ways to reach the n'th stair
- Python program to find the most occurring character and its count
- Python program to check if a given string is Keyword or not
- Python program to check whether a number is Prime or not
- Python Program to check Armstrong Number
- Python Program to check if given array is Monotonic
- Python program to check if given string is pangram
- Python Program to Check Prime Number
- Python Program to Count trailing zeroes in factorial of a number
- Python Program to Count number of binary strings without consecutive 1's