Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- SQRT_5 = math.sqrt(5)
- GOLDEN_NUMBER = (1 + SQRT_5) / 2
- """
- Fibonacci number is described as follows:
- Fn = 1 / sqrt(5) (pow(a,n) – pow(b,n))
- where: a = 1 / 2 (1 + sqrt(5)) and b = 1 / 2 (1 – sqrt(5))
- """
- def fib(n):
- return int(1 / SQRT_5 * (GOLDEN_NUMBER ** n - (-1 / GOLDEN_NUMBER) ** n))
- print(fib(10))
Add Comment
Please, Sign In to add comment