- 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

# C Program to Find the minimum sum of factors of a number?

The program to find the minimum sum of factors of a number. The logic for solving this problem is, find all the set of factors and adding them. For every set of factors, we will do the same and then compare all of them. Then find all the minimum of these sums.

Input: n=12 Output: 7

## Explanation

First find the factors of number n then sum them and try to minimize the sum. Following are different ways to factorize 12 and sum of factors in different ways.

12 = 12 * 1 = 12 + 1 = 13 12 = 2 * 6 = 2 + 6 = 8 12 = 3 * 4 = 3 + 4 = 7 12 = 2 * 2 * 3 = 2 + 2 + 3 = 7 Therefore minimum sum is 7

## Example

#include<iostream> using namespace std; int main() { int n = 12; int sum = 0; for (int i = 2; i * i <= n; i++) { while (n % i == 0) { sum += i; n /= i; } } sum += n; cout << sum; return 0; }

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

Advertisements