wsqgh @ 2022-12-26 14:55:35
#include<iostream>
using namespace std;
int main()
{
int k,n;
double i=1,S=0;
cin>>k;
while(S<k)
{
S+=1/i;
i++;
}
cout<<i<<endl;
return 0;
}
by ZQIN_P @ 2022-12-26 14:58:44
@wsqgh 使得 S_n>k。
by ZQIN_P @ 2022-12-26 15:02:04
把while(S<k)
改成while(S<=k)
by wsqgh @ 2022-12-26 15:04:07
@planet_over_for_ever 答案出现了问题,是不是我下面还要减一
by wsqgh @ 2022-12-26 15:05:52
@planet_over_for_ever 我已经通过了
by ZQIN_P @ 2022-12-26 15:07:53
@wsqgh AC了就行,其实不需要-1的
by dm72 @ 2023-02-12 19:52:44
#include<cstdio>
int main() {
int k,n=0;
scanf("%d",&k);
for(double Sn=0;Sn<=k;++n,Sn+=1.0/n);
printf("%d",n);
return 0;
}
应该是吧