P1035

· · 题解

P1035

额,毕竟我是纯为了刷水题的,所以发一个题解。

这道题并不难,可以用一个while来遍历分母,暂停循环的条件为n<=k(注意是<=,不然样例过不了,本人就是差点因为这个样例崩溃)

上代码!!

#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    double a = 1;
    double s = 2;
    while(a<=n){
        a+=1/s;
        s++;
    }
    cout << s-1;
    return 0;
}

AC!!