为什么60,求dalao纠错

P1035 [NOIP2002 普及组] 级数求和

wcx_is_god @ 2024-03-20 18:30:56

#include <bits/stdc++.h>
using namespace std;
int main() {
    int k;
    double c = 0;
    cin >> k;
    for (int i = 1;; i++) {
        c = 0;
        for (int j = 1; j <= i; j++) {
            c += 1.0 / j;
        }
        if (c > k) {
            cout << i;
            break;
        }
    }
    return 0;
}

by kkksc03_csc @ 2024-03-20 18:34:04

#include <iostream>
using namespace std;
int main(){
    int k,i=0;
    double sum=0;
    cin >>k;
   while(sum<=k){
        i++;
        sum+=1.0/i;
    }
    cout <<i;
    return 0;
}  

by xhz2018 @ 2024-04-29 19:26:02

#include<bits/c++.h>

int main()
{
    int k, n;
    double c = 0;
    cin >> k;
    for (n = 1; ; n++)
    {
        c += 1.0 / n;
        if(c > k * 1.0)
        {
            break;
        }

    }
    cout << n;
    return 0;
}

by xhz2018 @ 2024-04-29 19:28:48

刚发错了

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k, n;
    double c = 0;
    cin >> k;
    for (n = 1; ; n++)
    {
        c += 1.0 / n;
        if(c > k * 1.0)
        {
            break;
        }

    }
    cout << n;
    return 0;
}

by 45haotong @ 2024-05-16 21:24:25

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double s,n=0,x=0,y,z;
    cin>>s;
    while (n<=s)
    {
        x++;
        n+=1.0/x;
    }
    cout<<x;
}

|