CBY18106809989 @ 2019-08-28 09:03:15
各位大佬 为什么这样不行! 在线等!急!
using namespace std;
int main()
{
int i,K;
float sum=0;
cin>>K;
for(i=1;;i++)
{
sum+=1.0/i;
if(sum>K)
{
cout<<i;
break;
}
}
return 0;
}
by XMK_萌新 @ 2019-08-28 09:06:44
不行是什么意思 并没有ce啊
by XMK_萌新 @ 2019-08-28 09:08:12
也许精度不够?
by momentous @ 2019-08-28 09:08:42
by Suphx @ 2019-08-28 09:09:49
希望更丰富的展现?使用Markdown
by momentous @ 2019-08-28 09:09:58
我之前还是P党时写的代码:
var x:real;
i,n:longint;
begin
read(n);
while x<n do
begin
inc(i);
x:=x+1/i;
end;
writeln(i);
end.
by 斗神_君莫笑 @ 2019-08-28 09:10:01
希丰展?使MD
by Smile_Cindy @ 2019-08-28 09:13:48
请不要使用Markdown来强调头文件的重要性。
by Mitch谜团 @ 2019-08-28 09:15:50
希丰展?使MD
by C3765428 @ 2019-08-28 09:33:10
@CBY18106809989 ```
#include<cstdio>
int main() {
int k;
int n=0;
scanf("%d",&k);
for(double Sn=0;Sn<=k;++n,Sn+=1.0/n);
printf("%d",n);
return 0;
}
by 咕_gu @ 2019-09-18 16:53:34
#include<iostream>
using namespace std;
int main()
{
double Sn=0,K,n=0;
cin>>K;
while (Sn<=K){
n++;
Sn+=1/n;
}
cout<<(int)n;
return 0;
}