
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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 Articles
- 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?
- To find sum of even factors of a number in C++ Program?
- C Program for Find sum of odd factors of a number?
- C++ program for Find sum of odd factors of a number
- Java Program to Find sum of even factors of a number
- 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
- Find sum of even factors of a number using C++.
- Find sum of odd factors of a number using C++.
- 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