关于题目数据

P1035 [NOIP2002 普及组] 级数求和

sh_juruo @ 2023-02-19 15:56:48

https://www.luogu.com.cn/problem/P1035

这道题我的代码没过样例,输入1输出1,但是我却过了洛谷数据,代码如下

#include<bits/stdc++.h>
using namespace std;
int k,n,j=0;
double d=0.0,i=1.0;
int main(){
    scanf("%d",&k);
    while(d<k){
        d+=1/i;
        i++;j++;
    }
    printf("%d",j);
    return 0;
}

by Loser_Syx @ 2023-02-19 15:58:36

@sh_juruo d <= k


by Yun_Mengxi @ 2023-02-19 15:59:14

应该把d<k换成d<=k,因为题目要求S_n>k


by sh_juruo @ 2023-02-19 16:01:29

@Saint_ying_xtf

@Yun_Mengxi 好的,谢谢


|