Given a number N. The task is to find the sum of all factors of the given number N.
Input : N = 12 Output : 28 All factors of 12 are: 1,2,3,4,6,12 Input : 60 Output : 168
Approach: Suppose N = 1100, the idea is to first find the prime factorization of the given number N.
Therefore, prime factorization of 1100 = 22 * 52 * 11.
So, the formulae to calculate sum of all factors can be given as,
(20 + 21 + 22) * (50 + 51 + 52) * (110 + 111)
(upto the power of factor in factorization i.e. power of 2 and 5 is 2 and 11 is 1.)
= (1 + 2 + 22) * (1 + 5 + 52) * (1 + 11)
= 7 * 31 * 12
So, sum of all factors of 1100 = 2604
Below is the implementation of the above approach:
Sum of the factors is : 28
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.
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Generating all divisors of a number using its prime factorization
- Check if a number exists having exactly N factors and K prime factors
- Maximum number of prime factors a number can have with exactly x factors
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Prime factors of a big number
- Number which has the maximum number of distinct prime factors in the range M to N
- Generate K co-prime pairs of factors of a given number
- Check if all Prime factors of number N are unique or not
- Number of steps to convert to prime factors
- Check if there exists a number with X factors out of which exactly K are prime
- Product of unique prime factors of a number
- Maximum number of unique prime factors
- Super Ugly Number (Number whose prime factors are in given set)
- Number of factors of very large number N modulo M where M is any prime number
- Number less than equals to N with maximum product of prime factors
- Product of divisors of a number from a given list of its prime factors
- C Program for efficiently print all prime factors of a given number
- Efficient program to print all prime factors of a given number
- Number of distinct prime factors of first n natural numbers
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.