全TLE,求助!

P1035 [NOIP2002 普及组] 级数求和

FJRT2425 @ 2024-07-08 13:16:23

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int s,n,i=1;
    cin>>s;
    while(i++)
    {
        n+=1/i;
        if(n>s) break;
    }
    printf("%d",i);
    return 0;
}

by shaun2000 @ 2024-07-08 13:28:33

n你要定义为一个double啊,并且要初始化


by shaun2000 @ 2024-07-08 13:31:22

@FJRT2425


by FJRT2425 @ 2024-07-08 19:09:22

@shaun2000 感谢大佬!


|