We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The closed-form formula is the best way to solve this problem. It can be inaccurate for calculating exact values of Fibonacci numbers, but we need to calculate log10 of a Fibonacci number here and particular accuracy is not needed. Basically log10(phi^k/sqrt(5)) + 1 is a good estimate for the number of digits of a Fibonacci number and this formula is easily simplified to a linear equation to find k.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #25: N-digit Fibonacci number
You are viewing a single comment's thread. Return to all comments →
The closed-form formula is the best way to solve this problem. It can be inaccurate for calculating exact values of Fibonacci numbers, but we need to calculate log10 of a Fibonacci number here and particular accuracy is not needed. Basically log10(phi^k/sqrt(5)) + 1 is a good estimate for the number of digits of a Fibonacci number and this formula is easily simplified to a linear equation to find k.