'commit'
This commit is contained in:
17
TangDou/LuoGuBook/P1035_3.cpp
Normal file
17
TangDou/LuoGuBook/P1035_3.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user