from math import sqrt
n = int(input())
phi = (1 + sqrt(5))/2
fib_n = round((phi**n))
print(fib_n)
The above-mentioned code is not correct, it gives some nearer value to fib_n.
from math import sqrt
n = int(input())
phi = (1 + sqrt(5))/2
fib_n = round((phi**n)/sqrt(5))
print(fib_n)
This code works absolutely perfect after dividing by sqrt(5) in the 6th line.
My doubts are:
- What is the significance of dividing by sqrt(5) and why only sqrt(5) and not any other number?
- Can I solve the same thing using the floor or ceiling (or any other) and without dividing by root(5)?
Any help/guidance/resources are heavily appreciated!