= Solution
The expression is the <Binet formula> for the <Fibonacci numbers>. Compute the two roots and round the result to the nearest <integer>:
``
from math import sqrt
def binet(n):
phi = (1 + sqrt(5)) / 2
psi = (1 - sqrt(5)) / 2
return round((phi**n - psi**n) / sqrt(5))
``
The returned object is an integer. This <floating-point arithmetic> implementation correctly rounds the requested range through $n=50$; it is not an arbitrary-precision method for indefinitely large $n$. An integer recurrence is a useful independent numerical check.
Back to article page