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)) Articles by others on the same topic
There are currently no matching articles.