Given a number, find minimum sum of its factors.

Examples:

Input : 12 Output : 7Explanation: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 Input : 105 Output : 15

`// Java program to find minimum ` `// sum of product of number ` ` ` `public` `class` `Main { ` ` ` ` ` `// To find minimum sum of ` ` ` `// product of number ` ` ` `static` `int` `findMinSum(` `int` `num) ` ` ` `{ ` ` ` `int` `sum = ` `0` `; ` ` ` ` ` `// Find factors of number ` ` ` `// and add to the sum ` ` ` `for` `(` `int` `i = ` `2` `; i * i <= num; i++) { ` ` ` `while` `(num % i == ` `0` `) { ` ` ` `sum += i; ` ` ` `num /= i; ` ` ` `} ` ` ` `} ` ` ` `sum += num; ` ` ` ` ` `// Return sum of numbers ` ` ` `// having minimum product ` ` ` `return` `sum; ` ` ` `} ` ` ` ` ` `// Driver program to test above function ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `num = ` `12` `; ` ` ` `System.out.println(findMinSum(num)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

**Output:**

7

Please refer complete article on Find minimum sum of factors of number for more details!

## Recommended Posts:

- Java Program to Find sum of even factors of a number
- Program for Find sum of odd factors of a number
- Java Program to find Product of unique prime factors of a number
- Java Program for Number of elements with odd factors in given range
- Java Program for efficiently print all prime factors of a given number
- Java Program to Find the Number Occurring Odd Number of Times
- Java Program for Minimum number of jumps to reach end
- Java Program for Program to find area of a circle
- Java Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Java Program to find sum of array
- Java Program to Find sum of Series with n-th term as n^2 - (n-1)^2
- Java Program for Sum the digits of a given number
- Java Program for Find largest prime factor of a number
- Java Program to Find Maximum Odd Number in Array Using Stream and Filter
- Java Program for How to check if a given number is Fibonacci number?
- Java Program for Program to calculate area of a Tetrahedron
- Java Program for Program for array rotation
- Program to find the sum of the series (1/a + 2/a^2 + 3/a^3 + ... + n/a^n)
- Java Program for Range sum queries without updates
- Java Program for cube sum of first n natural numbers