Garfeild001 @ 2021-08-11 20:00:26
k=int(input()) n=1 s=0 while s<=k: for i in range(1,n+1): j=1/i s+=j n+=1 print(n)
by 159号程序员 @ 2021-08-11 20:01:49
k=int(input())
n=1
s=0
while s<=k:
for i in range(1,n+1):
j=1/i
s+=j
n+=1
print(n)
by Garfeild001 @ 2021-08-11 20:03:30
@159号程序员 我和这个一样,但通过不了
by 159号程序员 @ 2021-08-11 20:04:17
@Garfeild001 对不起,我不太懂py,只能帮您优化下排版了/cy
by _l_l_l_l_l_ @ 2021-08-11 20:09:30
@Garfeild001 注:我也不懂Python
可能是for i in range(1,n+1):
这么做我猜会无限循环
by Universal_xtr @ 2021-08-11 20:10:12
@Garfeild001
k=int(input())
s=0
cnt=1
while s<=k:
s+=1/cnt
cnt+=1
cnt-=1
print(cnt)
不需要那么麻烦。。。
亲测通过
by Garfeild001 @ 2021-08-11 20:41:41
@Universal_xtr 谢谢大神