※ 引述《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
```