İçeriğe geç

Python ile Project Euler Soru 2 Çözümü

Soru:

https://projecteuler.net/problem=2
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.
———————————–
Fibonacci dizisindeki her yeni terim, önceki iki terim eklenerek üretilir. 1 ve 2 ile başlayarak ilk 10 terim şöyle olacaktır:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …
Değerleri dört milyonu aşmayan Fibonacci dizisindeki terimleri dikkate alarak, çift sayıların toplamını bulun.

# Project Euler - 2
a = 1
b = 2
toplam = 0
while b < 4000000:
    if b % 2 == 0:
        toplam += b
    a, b = b, a + b

print(toplam)
1.393 Gösterim  
Tarih:algoritmalar ve programlamaya girişprogramlamaProject EulerPython

İlk Yorumu Siz Yapın

Bir cevap yazın

E-posta hesabınız yayımlanmayacak.

This site uses Akismet to reduce spam. Learn how your comment data is processed.