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 :
n = (a1^p1) * (a2^p2) *…….*(an^pn), where a1, a2…an all are prime factors and p1, p2, .. pn are integral power of them as pi being integral power of ai in factorization of n.
So, for this factorization we have formula to find total number of divisor of n and that is:
(p1+1) * (p2+1) *….*(pn+1).
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 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.
- 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
- Check if a number is divisible by all prime divisors of another number
- 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
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find the total number of composite factor for a given number
- First triangular number whose number of divisors exceeds N
- Number of divisors of a given number N which are divisible by K
- Count total divisors of A or B in a given range
- Sum of divisors of factorial of a number
- Find the sum of the number of divisors
- Find number from its divisors
- Sum of all the prime divisors of a number
- Sum of multiplication of triplet of divisors of a number