Python Program for Find Minimum Sum of Factors of Number (original) (raw)

Last Updated : 31 Oct, 2025

Given a number, the task is to find the minimum possible sum of its factors when multiplied together to form the number. For example, for 12, it can be written as 2 × 6, 3 × 4, or 2 × 2 × 3. The sums of these factors are 8, 7, and 7 respectively, and hence the minimum sum is 7.

Let’s explore different methods to solve this problem efficiently.

Prime Factorization Method

This method repeatedly divides the number by its smallest factor to collect all prime factors. Then, their sum gives the minimum possible factor sum representation.

Python `

num = 12 res = 0 i = 2

while i * i <= num: while num % i == 0: res += i num //= i i += 1

if num > 1: res += num

print(res)

`

**Explanation:

Using Factor Pairs

This method checks all factor pairs up to the square root of the number. For each valid pair (i, num // i), it computes the sum and keeps track of the smallest one found.

Python `

num = 12 res = num

for i in range(2, int(num ** 0.5) + 1): if num % i == 0: factor = num // i res = min(res, i + factor)

print(res)

`

**Explanation:

Brute Force Approach

This method checks all divisors from 1 to n. For each divisor, it calculates the sum of the pair (i, n // i) and stores the minimum.

Python `

num = 12 res = num

for i in range(1, num + 1): if num % i == 0: res = min(res, i + num // i)

print(res)

`

**Explanation:

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