def problem25():
    for n, f in enumerate(fib()):
        if (floor(log10(f if f != 0 else 1)) + 1) == 1000:
            return n
Beispiel #2
0
# Problem 2
# 19 October 2001

# Each new term in the Fibonacci sequence is generated by adding the previous two terms.
# By starting with 1 and 2, the first 10 terms will be:

# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

# By considering the terms in the Fibonacci sequence whose values do not exceed four million,
# find the sum of the even-valued terms.

from common import fib
from itertools import takewhile
print(sum(takewhile(lambda x: x <= 4000000, (x for x in fib() if x % 2 == 0))))
def foo():
    for i, f in enumerate(fib(10**1000)):
        if len(str(f)) >= 1000:
            return i, f
Beispiel #4
0
def answer():
    i = 0
    for n in fib():
        if len(str(n)) == 1000: return i
        i += 1
Beispiel #5
0
# 导入模块
import sys

import common
# 一个模块只会被导入一次,不管你执行了多少次import。这样可以防止导入模块被一遍又一遍地执行。
# 现在可以调用模块里包含的函数了
common.print_func("Runoob")
common.fib(1000)
print(common.fib2(1000))

# 内置的函数 dir() 可以找到模块内定义的所有名称。以一个字符串列表的形式返回:
# 如果没有给定参数,那么 dir() 函数会罗列出当前定义的所有名称:
print(dir(common))
Beispiel #6
0
#! /usr/bin/env python

from common import fib

for n in xrange(4000, 5001):
  fibn = fib(n)
  #print n, fibn, len(str(fibn))
  if (len(str(fibn)) == 1000):
    print n, fibn, len(str(fibn))
Beispiel #7
0
#!/usr/bin/env python

from common import fib
from itertools import count

MAX = 1000

for a in count(1):
    f = fib(a)
    l = len(str(f))

    if l == 1000:
        print(a)
        break