Guest User

Untitled

a guest
May 27th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. import math
  2.  
  3. SQRT_5 = math.sqrt(5)
  4. GOLDEN_NUMBER = (1 + SQRT_5) / 2
  5.  
  6. """
  7. Fibonacci number is described as follows:
  8. Fn = 1 / sqrt(5) (pow(a,n) – pow(b,n))
  9. where: a = 1 / 2 (1 + sqrt(5)) and b = 1 / 2 (1 – sqrt(5))
  10. """
  11. def fib(n):
  12. return int(1 / SQRT_5 * (GOLDEN_NUMBER ** n - (-1 / GOLDEN_NUMBER) ** n))
  13.  
  14. print(fib(10))
Add Comment
Please, Sign In to add comment