Contents
Problem
簡而言之就是要用 不重複 的數字,和為 n ,且乘積最大。
Solution
先直接放 2,3,4,… ,不要超過 n。(比起單一個數字加 1,多一項比較好)
接著看相差多少,因為數字不能重複,所以從最後一項開始,一個一個加一,直到第一個,如此循環。
ex.
n = 8
2 + 3 = 5
diff = 8 - 5 = 3
diff = 2: 2 + 4 = 6
diff = 1: 3 + 4 = 7
diff = 0: 3 + 5 = 8
Ans: 3 5
Code
1 |
|