这道题主要考察二分查找,由于使用python语言,我们可以使用库,很方便。先打一个表,记录,之后使用bisect_left进行查找就可以了。
代码很短,如下(也说明了该库的方便与快捷):
import bisect
f = [0]
for i in range(1, 1000):
f.append(f[-1]+1/(i+1))
while True:
c = float(input())
if c == 0:
break
print(bisect.bisect_left(f, c), 'card(s)')