Problem Description:
Given a positive integer n, break it into the sum of at least, positive integers and maximize the product of those inte Gers. Return The maximum product you can get.
For example, given n = 2, return 1 (2 = 1 + 1); Given n =
ten, return 36 (10 = 3 + 3 + 4).
Note:you may assume, N is not less than 2.
Hint:
1) There is a simple O (n) solution to this problem.
2) You may check the breaking results for n ranging from 7 to discover the regularities.
A non-negative integer n is split into the sum of at least two integers, and the maximum value of the product of each number of the partitions is obtained.
Problem Solving:
class Solution {public:int integerbreak (int n) {if (n < 4) return n-1;
int res = 1;
while (n > 2) {//See n contains number of 3, multiply them until n<=2 res *= 3;
N-= 3;
if (n = = 0) return res;//n can be divisible 3,res is the individual 3 multiplied if (n = = 1) return (RES/3) * 4;//In addition to 3 1, one of 3 plus 1 into 4 and multiply if (n = = 2) return res * 2;//except 3 + 2, you can directly multiply 2 with res}};