volver

Even Fibonacci Numbers

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.


El calculo de los numeros de fibonacci se puede hacer fácilmente con python, usando un array y añadiendo n terminos:

f0=1, f1=1, entonces fn=fn1+fn2

def fibo(n):
    numbers = [1, 1]
    while True:
        new = numbers[-1]+numbers[-2]
        if new<n:
            numbers.append(new)
        else:
            break
    return numbers
sum([x for x in fibo(4000000) if x%2==0])