Given an integer
n
, break it into the sum ofk
positive integers, wherek >= 2
, and maximize the product of those integers.
Return the maximum product you can get.
Constraints:
2 <= n <= 58
給一整數
n
,將他分割成k
份,其中k >= 2
且為正整數,最大化這些整數的乘積。
回傳你可能得到的最大乘積。
限制:
2 <= n <= 58
2
只能分成 1 * 1 = 1
,沒得選擇3
的最大值是 1 * 2 = 2
4
的最大值是 2 * 2 = 4
5
的最大值是 2 * 3 = 6
5
的情況,就知道要拆成 2 * 3
6
的最大值是 3 * 3 = 9
,而不是 2 * 2 * 2 = 8
6
的情況,就知道要拆成 3 * 3
7
的最大值是 3 * 3 * 2
3
,但是剩下 4
的時候不能分
4 > 3 * 1
2
和 3
本身也是特例,因為一定至少要分成兩份LeetCode
C++