欧拉项目问题25https://projecteuler.net/problem=25,非常简单。要解决的问题是:
What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
但我的回答是错的,我不知道为什么。你知道吗
再简单不过了,我只是得到了错误的答案
def fib_gen(i=1, j=1):
yield 1
yield 1
while 1:
i, j = i+j, i
yield i
for i, f in enumerate(fib_gen()):
if f < (10**1000):
pass
else:
if f > (10**1000-1):
print(i+1, f)
break
我的答案4787
我想正确答案是4782。你知道吗
UPDATE never mind. I figured out 10**1000 is 1001 digits number
试试这个一个:-你知道吗
如果您使用
if f > (10**(1000-1)):
,您将得到4782。你知道吗相关问题 更多 >
编程相关推荐