Question: Given an integer $n$, break it into the sum of $k$ positive integers, where $k \geq 2$, and maximize the product of those integers.
Return the maximum product you can get.
Comment:
The key observation is the fact that for any integer $n \geq 4$, it has the property such that $3\cdot(n - 3) > n$ which means breaking it into two integers $3$ and $n - 3$ makes the product larger while keeping the sum unchanged.
If $n - 3$ is still greater than $4$, we can break it into $3$ and $n - 6$, resulting in $3 \cdot 3 \cdot (n - 6)$ and so on, until we cannot break it (less than or equal to $4$) anymore.
I was just wondering, why is the above observation true/valid, from an academic/mathematical perspective
Take $n = 10$ and $k = 4$ for example. If we use your method, we have $3 \cdot 3 \cdot 3 \cdot 1 = 27$. If we try another way, we can have $2 \cdot 2 \cdot 3 \cdot 3 = 36$.
My hypothesis (without the $k$ constraint):
To maximize, break $n$ into $\lfloor\frac{n}{2}\rfloor$ and $\lceil\frac{n}{2}\rceil$. Then, for each number, repeat until the number is either $2$, $3$, or $4$.
The reason why $2$ should not be broken is because it breaks into two $1$'s, and the product is $1$ which is less than $2$. For $3$, the maximum product if broken is $2$ which is less than $3$. For $4$, the maximum product is $4$ since $2 + 2 = 4$ and $2 \cdot 2 = 4$.
Let's have $n = 25$. Breaking it, we have $12$ and $13$. Breaking $12$, we have two $6$'s, where breaking $6$ gives two $3$'s. Hence, $12$ breaks into $[3,3,3,3]$. Breaking $13$, we have $6$ and $7$. Breaking $6$ gives two $3$'s and breaking $7$ gives $3$ and $4$. Hence, $13$ breaks into $[3, 3, 3, 4]$.
Multiplying all, we have $3^{7}\cdot 4 = 8748$.
I am still trying to prove that this is true. Hopefully, someone might do it.
With the $k$ constraint, the maximum product is $(\lfloor\frac{n}{k}\rfloor)^{k - (n \bmod k)}(\lfloor\frac{n}{k}\rfloor + 1)^{(n \bmod k)}$ where $0 \leq (n \bmod k) < n$. In my example where $n = 10$ and $k = 4$, $10 \bmod 4 = 2$, hence the maximum product is $2^{4 - 2}(2 + 1)^{2} = 2^{2}3^{2}$. In @user64494 's example where $n = 40$ and $k = 6$, $40 \bmod 6 = 4$, hence $6^{6 - 4}(6 + 1)^{4} = 6^{2}7^{4}$. I don't know how to prove this if this gives the maximum product.This was already mentioned by @MatthewLeingang .