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