※ 引述《dont (dont)》之铭言:
: ※ 引述《JerryChungYC (JerryChung)》之铭言:
: : https://leetcode.com/problems/2-keys-keyboard
: : 650. 2 Keys Keyboard
思路:
靠杯为什么一堆人会想到要DP解
好可怕==
这题不就质因子分解加起来
:(
只剩我在写这种国小作法了
class Solution {
public:
int minSteps(int n) {
//find factor of n
if(n == 1) return 0;
vector<int> factor;
for(int i = 2; i*i <= n; i++){
while(n % i == 0){
factor.push_back(i);
n /= i;
}
}
if(n != 1) factor.push_back(n);
return accumulate(factor.begin(), factor.end(), 0);
}
};