Files
python/TangDou/LuoGuBook/P1035_3.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

17 lines
440 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}