景驰第二题求助。。。
景驰第二题求助。。。
int main() {
int n;
cin >> n;
int re;
if (n <= 1)
re = 0;
else if (n == 2)
re = 3;
else {
re = 0;
vector<int> dp(n + 1, 0);
for (int i = 2;i <= n;i++) {
dp[i] = i + 1;
for (int j = i - 1;j>1;j--) {
if (i%j == 0) {
dp[i] = min(dp[i], dp[j] + 1 + (i / j));
}
}
}
re = dp[n];
}
cout << re;
return 0;
}
#笔试题目#int n;
cin >> n;
int re;
if (n <= 1)
re = 0;
else if (n == 2)
re = 3;
else {
re = 0;
vector<int> dp(n + 1, 0);
for (int i = 2;i <= n;i++) {
dp[i] = i + 1;
for (int j = i - 1;j>1;j--) {
if (i%j == 0) {
dp[i] = min(dp[i], dp[j] + 1 + (i / j));
}
}
}
re = dp[n];
}
cout << re;
return 0;
}