※ 引述《JerryChungYC (JerryChung)》之銘言:
: https://leetcode.com/problems/2-keys-keyboard
: 650. 2 Keys Keyboard
: 思路:
: 知道在做什麼但沒有想法 所以先從小數字實際算一次找規律
: 結果發現似乎是質因數加總的答案 於是就直接go
: 如 12 = 2 * 2 * 3 , 2 + 2 + 3 = 7 答案就是 7
: 如 8 = 2 * 2 * 2 , 2 + 2 + 2 = 6 答案 6 (cpcpcp) or (cpcppp)
6 = 1 * 6 = [CPPPPP] = 6
= 2 * 3 = [CP] + [CPP] = 5
24 = 2 * 2 * 2 * 3 = [CP] + [CP] + [CP] + [CPP] = 9
= 2 * 12 = [CP] + [CPPPPPPPPPPP] = 14
= 3 * 8 = [CPP] + [CPPPPPPP] = 11
= 4 * 6 = [CPPP] + [CPPPPP] = 10
```python
class Solution:
def minSteps(self, n: int) -> int:
ans = 0
i = 2
for i in range(2, 1+n):
while n % i == 0:
ans += i
n //= i
if n == 1:
break
return ans
```