- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Python Program for Find sum of odd factors of a number

In this article, we will learn about the solution to the problem statement given below −

## Problem statement

Given a number input n, the task is to Find the sum of odd factors of a number.

Here we first need to eliminate all the even factors.

To remove all even factors, we repeatedly divide n till it is divisible by 2. After this step, we only get the odd factors of the number.

Below is the implementation −

## Example

import math def sumofoddFactors( n ): #prime factors res = 1 # ignore even factors while n % 2 == 0: n = n // 2 for i in range(3, int(math.sqrt(n) + 1)): count = 0 curr_sum = 1 curr_term = 1 while n % i == 0: count+=1 n = n // i curr_term *= i curr_sum += curr_term res *= curr_sum # n is a prime number. if n >= 2: res *= (1 + n) return res # main n = 27 print(sumofoddFactors(n))

## Output

41

All the variables are declared in the global frame as shown in the figure given below −

## Conclusion

In this article, we learnt about the approach to Find sum of odd factors of a number

- Related Questions & Answers
- C Program for Find sum of odd factors of a number?
- C++ program for Find sum of odd factors of a number
- Python Program for Find sum of even factors of a number
- Python Program for Find minimum sum of factors of number
- Find sum of odd factors of a number using C++.
- Find sum of even factors of a number in Python Program
- C++ Program to find sum of even factors of a number?
- Java Program to find minimum sum of factors of a number
- Java Program to Find sum of even factors of a number
- Python Program for Number of elements with odd factors in the given range
- To find sum of even factors of a number in C++ Program?
- C Program to Find the minimum sum of factors of a number?
- Find sum of even factors of a number using C++.
- Python Program for Product of unique prime factors of a number
- Find minimum sum of factors of number using C++.

Advertisements