Skip to content

Commit c037c11

Browse files
authored
Update 343-integer-break.js
1 parent 05a559a commit c037c11

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

343-integer-break.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ const integerBreak = function(n) {
5050
}
5151
return rem === 0 ? Math.pow(3, num) : Math.pow(3, num) * rem
5252
};
53+
54+
/**
55+
56+
If an optimal product contains a factor f >= 4,
57+
then you can replace it with factors 2 and f-2 without losing optimality,
58+
as 2*(f-2) = 2f-4 >= f. So you never need a factor greater than or equal to 4,
59+
meaning you only need factors 1, 2 and 3 (and 1 is of course wasteful and you'd only use it for n=2 and n=3, where it's needed).
60+
61+
For the rest I agree, 3*3 is simply better than 2*2*2, so you'd never use 2 more than twice.
62+
63+
*/

0 commit comments

Comments
 (0)