Loading problem...
You are given a positive integer n. Your task is to split this integer into a sum of at least two positive integers, and then calculate the product of all those integers. The goal is to maximize this product.
More formally, you need to find positive integers a₁, a₂, ..., aₖ (where k ≥ 2) such that:
Return the maximum possible product that can be achieved through any valid partition of n.
This problem explores the mathematical relationship between addition and multiplication. While both operations seem simple, the way we split a number dramatically affects the resulting product. Understanding which partitions yield optimal products reveals elegant patterns in number theory and has practical applications in resource allocation and optimization problems.
n = 21The only way to partition 2 into at least two positive integers is 2 = 1 + 1. The product is 1 × 1 = 1. This is the maximum (and only) possible product.
n = 1036The optimal partition is 10 = 3 + 3 + 4. The product is 3 × 3 × 4 = 36. Other partitions like 10 = 5 + 5 give 25, and 10 = 2 + 2 + 2 + 2 + 2 gives 32, but 36 is the maximum achievable.
n = 69The optimal partition is 6 = 3 + 3, giving a product of 3 × 3 = 9. Compare this to 6 = 2 + 2 + 2 which gives 8, or 6 = 4 + 2 which gives 8. Partitioning into threes yields the best result.
Constraints