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
def find_min_sum(num):
min_sum = num
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
factor = num // i
min_sum = min(min_sum, i + factor)
return min_sum
number = 16
result = find_min_sum(number)
print("The minimum sum of factors for", number, "is", result)
Output:
8
Time Complexity : O(n 1/2 * log n)
Auxiliary Space : O(1) Please refer complete article on Find minimum sum of factors of number for more details!
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Last Updated :
01 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Add Your Comment
Please Login to comment...