imbecile @ 2020-05-17 13:52:55
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n=1,k;
double s=0.0;
cin>>k;
while(s<k)
{
s+=double(1/n);
n++;
}
cout<<n;
}
by 159号程序员 @ 2020-05-17 14:00:34
@zengxiangtuo
by 江户川·萝卜 @ 2020-05-17 14:01:22
1/0 RE警告
by 江户川·萝卜 @ 2020-05-17 14:02:14
先把n赋值为0,然后while里面先++
by imbecile @ 2020-05-17 14:02:16
@159号程序员 为什么
by Adhara @ 2020-05-17 14:02:30
@159号程序员 你告诉我可以1/0
?
by imbecile @ 2020-05-17 14:02:47
@江户川·萝卜 不一样吗?
by Adhara @ 2020-05-17 14:02:57
@zengxiangtuo 直接输出的时候减一就好了
by 江户川·萝卜 @ 2020-05-17 14:03:30
@zengxiangtuo 不一样,您的程序当Sn>k的时候n还要++,但是根据题意当Sn>k的时候就直接终止
by imbecile @ 2020-05-17 14:03:56
@Adhara 艹,害我改了
by Adhara @ 2020-05-17 14:04:27
@zengxiangtuo 两种写法没有本质区别的,您先想到哪种就写哪种吧