[Math] Number of Fibonacci numbers in a range

fibonacci-numbers

The definition of the Fibonacci numbers is given by:

$$\begin{align}f_1 &= 1;\\ f_2 &= 2;\\
f_n &= f_{n-1} + f_{n-2},\qquad (n >= 3);
\end{align}$$

now we are given two numbers $a$ and $b$, and we have to calculate how many Fibonacci numbers are in the range $[a,b]$. How can we calculate it?

Best Answer

We know that $F_n\approx \frac {\phi^n}{\sqrt 5}$, so given $a$, the next larger Fibonacci number is $F_k$, where $k= \left \lceil\frac {\log (a\sqrt 5)}{\log \phi }\right \rceil$. Similarly the $F_m$ below $b$ is $m= \left \lfloor\frac {\log (b\sqrt 5)}{\log \phi }\right \rfloor$, then there are $m-k+1$ between $a$ and $b$. You have to think about what you want if $a$ or $b$ are themselves Fibonacci numbers.