思路:没什么好讲的,一看就懂,但是注意个细节,这里要用双精度的double才能通过
#include<iostream>
using namespace std;
int main() {
int k;
cin >> k;
double n = 0;
double sum = 0;
while (sum <= k) {
n++;
sum += 1 / n;
}
cout << n;
}
思路:没什么好讲的,一看就懂,但是注意个细节,这里要用双精度的double才能通过
#include<iostream>
using namespace std;
int main() {
int k;
cin >> k;
double n = 0;
double sum = 0;
while (sum <= k) {
n++;
sum += 1 / n;
}
cout << n;
}