If we know the break numbers k, the max product will be the case when each number is n/k. Compare all ks.

...

class Solution {

public:

int integerBreak(int n) {

int b=2;

int res=0;

while (true)

{

int num=1;

int cur=n;

for (int i=b;i>=1;i--)

{

num=num*(cur/i);

cur=cur-cur/i;

}

if (res<num) {res=num;b++;}

else break;

}

return res;

}

};

...