0分!

P1035 [NOIP2002 普及组] 级数求和

luoguofwangliming @ 2025-01-04 16:36:20

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,n=1;
    cin>>k;
    double b=0;
    while (b>k)
    {
        b=b+1.0/n;
        n++;
    }
    cout<<n;
    return 0;
}

by oldhorse1989 @ 2025-01-04 16:47:55

条件改为b<=k

输出为n-1


by xyx404 @ 2025-01-04 16:49:15

@luoguofwangliming

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double k,n=0;
    cin>>k;
    double b=0;
    while (b<=k)
    {
        n++;
        b=b+1/n;
    }
    cout<<n;
    return 0;
}

by msc120204 @ 2025-01-04 16:53:43

零分!


by zhouyixuan11 @ 2025-01-04 16:56:43

@xyx404 1.0/n


by xyx404 @ 2025-01-04 16:58:35

@zhouyixuan11我交过了...n 是 double 类型的


by zhouyixuan11 @ 2025-01-04 17:03:06

@xyx404 眼睛聋了,当我没说


|