Given an integer n, split it into the sum of k positive integers with k >= 2, and make the product of those integers as large as possible. Return the largest product.
Given an integer n, split it into the sum of k positive integers with k >= 2, and make the product of those integers as large as possible. Return the largest product.
Example 1:
Input: {"n":2}
Output: 1
Constraints:
2≤n≤58
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":2}
dp[k] will hold the largest product for a rope of length k, cut into at least two pieces. Fill it for k = 2 to 2.
rope of length 2
2
Where should the cuts go so the pieces multiply to the most?