You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
440 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
double s; // double类型因为是分数计算
int main() {
//数据上限k
int k;
cin >> k;
//枚举
int n;
for (n = 1;; n++) { // 1、n没有上限还在用for循环
s += 1.0 / n; // 2、1 / n--> 0 1.0 / n=0.5 0.33
if (s > k) break; //这个是结束条件,此时结束循环
}
cout << n << endl;
return 0;
}