Number of Fibonacci numbers in a range 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?
 A: 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.
A: This question is asked in Skiena's programming challenges. Now, to find the $ n^{\text{th}} $ fibonacci number, we have the following closed form expression.
$$ \Large F(n) = \dfrac{1}{\sqrt{5}} \left( \left( \dfrac{1 + \sqrt{5}}{2}\right)^n - \left( \dfrac{1 - \sqrt{5}}{2} \right)^n\right) $$
Now, given $ F(n) $, we can find approximately the index of the closest fibonacci number to it. Therefore, we find one $ n_1 $ such that $ F(n_1) = a $ and another $n_2 $ such that $ F(n_2) = b $. Then our answer is $\mathsf{round(n_2)} - \mathsf{round(n_1)}$ where $ \mathsf{round(x)} $ find the nearest integer to $ x $.
