Problem 357
Integer Break
Medium · 20 pts · Math, Dynamic Programming, Greedy
Problem
Split the integer N into the sum of at least two positive integers, and maximise the product of those integers. For example, 10 = 3 + 3 + 4 gives a product of 36, which is the best possible. Print the maximum product. A dynamic-programming solution works, and so does the observation that using as many 3s as possible (with 2s for the remainder) is optimal.
Input
A single integer N.
Output
Print the maximum product.
Constraints
2 <= N <= 58
Example input
10
Example output
36
Explanation
10 can be split as 3 + 3 + 4, and 3 · 3 · 4 = 36. No other split of 10 gives a larger product.