求助 TLE

P1035 [NOIP2002 普及组] 级数求和

Lily95 @ 2022-08-05 16:04:35

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

by Hisaishi_Kanade @ 2022-08-05 16:06:09

1/n\to1.0/n

int类型整除是下取整


by Lily95 @ 2022-08-07 18:54:41

@bye_wjx 懂了,感谢!


|