※ 引述《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);
}
};