{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Every third fibonacci number is even. Since $F_n = F_{n-3} * 4 + F_{n-6}$, we initialy calculate $F_3$ and $F_6$ then $F_9 = F_6 * 4 + F_3$, $F_{12} = F_9 * 4 + F_6$ etc..." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "def Fn(Fn_3, Fn_6):\n", " return Fn_3 * 4 + Fn_6\n", "Fn_6 = 0\n", "Fn_3 = 2\n", "sum = Fn_6 + Fn_3\n", "while True:\n", " f = Fn(Fn_3, Fn_6)\n", " if f > 4_000_000:\n", " break\n", " sum += f\n", " Fn_6 = Fn_3\n", " Fn_3 = f" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" }, "title": "Even Fibonacci Numbers" }, "nbformat": 4, "nbformat_minor": 4 }