Given a positive integer n, we have to find the total number of divisors for n.
Input : n = 25 Output : 3 Divisors are 1, 5 and 25. Input : n = 24 Output : 8 Divisors are 1, 2, 3, 4, 6, 8 12 and 24.
First of all store all primes from 2 to max_size in an array so that we should only check for the prime divisors. Now we will only wish to calculate the factorization of n in following form:
where ai are prime factors and pi are integral power of them.
So, for this factorization we have formula to find total number of divisor of n and that is:
Reference : Number of divisors.
This article is contributed by Shivam Pradhan (anuj_charm). 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 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.
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Count total divisors of A or B in a given range
- Find sum of divisors of all the divisors of a natural number
- Check if a number has an odd count of odd divisors and even count of even divisors
- Divisors of n-square that are not divisors of n
- Maximum possible prime divisors that can exist in numbers having exactly N divisors
- Check if count of even divisors of N is equal to count of odd divisors
- Total ways of choosing X men and Y women from a total of M men and W women
- Querying maximum number of divisors that a number in a given range has
- Find the largest good number in the divisors of given number N
- Number of divisors of a given number N which are divisible by K
- Find the total number of composite factor for a given number
- Count elements in the given range which have maximum number of divisors
- Program to find count of numbers having odd number of divisors in given range
- Count of Fibonacci divisors of a given number
- Count of square free divisors of a given number
- Product of divisors of a number from a given list of its prime factors
- Count of the non-prime divisors of a given number
- Total money to be paid after traveling the given number of hours
- Total number of unit cells covered by all given Rectangles