Given a number n, the task is to find the odd factor sum.
Input : n = 30 Output : 24 Odd dividers sum 1 + 3 + 5 + 15 = 24 Input : 18 Output : 13 Odd dividers sum 1 + 3 + 9 = 13
Prerequisite : Sum of all the factors of a number
As discussed in above mentioned previous post, sum of factors of a number is
Let p1, p2, … pk be prime factors of n. Let a1, a2, .. ak be highest powers of p1, p2, .. pk respectively that divide n, i.e., we can write n as n = (p1a1)*(p2a2)* … (pkak).
Sum of divisors = (1 + p1 + p12 ... p1a1) * (1 + p2 + p22 ... p2a2) * ............................................. (1 + pk + pk2 ... pkak)
To find sum of odd factors, we simply need to ignore even factors and their powers. For example, consider n = 18. It can be written as 2132 and sun of all factors is (1)*(1 + 2)*(1 + 3 + 32). Sum of odd factors (1)*(1+3+32) = 13.
To remove all even factors, we repeatedly divide n while it is divisible by 2. After this step, we only get odd factors. Note that 2 is the only even prime.
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 number of factors of N when location of its two factors whose product is N is given
- Maximum number of prime factors a number can have with exactly x factors
- Queries on sum of odd number digit sums of all the factors of a number
- Check if a number exists having exactly N factors and K prime factors
- Expressing a number as sum of consecutive | Set 2 (Using odd factors)
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Sum of all odd factors of numbers in the range [l, r]
- Number of elements with odd factors in given range
- Check whether count of odd and even factors of a number are equal
- Find minimum sum of factors of number
- Find sum of even factors of a number
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Number of factors of very large number N modulo M where M is any prime number
- Sum of M maximum distinct digit sum from 1 to N that are factors of K
- Find four factors of N with maximum product and sum equal to N | Set-2
- Find four factors of N with maximum product and sum equal to N
- Find four factors of N with maximum product and sum equal to N | Set 3
- Find prime factors of Array elements whose sum of exponents is divisible by K
- Find sum of exponents of prime factors of numbers 1 to N
- Average of odd numbers till a given odd number
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.