{ "cells": [ { "cell_type": "markdown", "id": "b5da29ec", "metadata": {}, "source": [ "# [1000-digit Fibonacci Number](https://projecteuler.net/problem=25)\n", "\n", "This problem can be solved with a scientific calculator!\n", "\n", "We're looking at [Fibonacci numbers](https://en.wikipedia.org/wiki/Fibonacci_sequence) again, after last seeing them in [problem 2](https://projecteuler.net/problem=2). Our goal is to find the index of the first 1000 digit number in the sequence. Mathematically, we can state this is as the lowest $n$ such that\n", "$$1+\\log{F_n} \\geq 1000$$\n", "(Here, $\\log$ is the base 10 logarithm).\n", "\n", "To assist in finding $n$, we can employ Binet's formula:\n", "$$F_n = \\frac{\\phi^n - (-\\phi)^{-n}}{\\sqrt{5}}$$\n", "Here, $\\phi$ is the [golden ratio](https://en.wikipedia.org/wiki/Golden_ratio).\n", "\n", "Binet's formula is exact, but we can make our work a little easier by approximating.\n", "$$F_n \\approx \\frac{\\phi^n}{\\sqrt{5}}$$\n", "This approximation works since $(-\\phi)^{-n}$ approaches 0 as $n$ increases. This also means this approximation gets more accurate as $n$ increases, which is especially convenient since we're looking for a large $n$. Substituting this approximation into the above inequality, we have\n", "$$1 + \\log{\\frac{\\phi^n}{\\sqrt{5}}} \\geq 1000$$\n", "\n", "Now with a little bit of algebra, we can solve for $n$.\n", "$$n \\geq 999\\log_{\\phi}10 + \\log_{\\phi}\\sqrt{5}$$\n", "If you're trying to solve this with a scientific calculator, you probably don't have a $\\log_{\\phi}$ button (*please let me know if you do*), but we can just use the [logarithmic change of base formula](https://en.wikipedia.org/wiki/List_of_logarithmic_identities). This ends up getting us\n", "$$n \\geq 4781.85927\\ldots$$\n", "Therefore, we want $n=4782$.\n", "\n", "## Relevant sequences\n", "* Fibonacci numbers: [A000045](https://oeis.org/A000045)\n", "\n", "#### Copyright (C) 2025 filifa\n", "\n", "This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)." ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 9.5", "language": "sage", "name": "sagemath" }, "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.11.2" } }, "nbformat": 4, "nbformat_minor": 5 }