Skip to content
Related Articles

Related Articles

Python Program for Find minimum sum of factors of number

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Hard
  • Last Updated : 22 Jun, 2022

Given a number, find minimum sum of its factors.
Examples: 
 

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

 

Python3




# Python program to find minimum
# sum of product of number
  
# To find minimum sum of
# product of number
def findMinSum(num):
    sum = 0
     
    # Find factors of number
    # and add to the sum
    i = 2
    while(i * i <=num):
        while(num % i == 0):
            sum += i
            num //= i
        i += 1
    sum += num
     
    # Return sum of numbers
    # having minimum product
    return sum
 
# Driver Code
num = 12
print (findMinSum(num))
 
# This code is contributed by Sachin Bisht

Output: 
 

7

Time Complexity: O(n1/2 * log n)

Auxiliary Space: O(1)

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!