Advertisement
tsounakis

Untitled

Dec 14th, 2019
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. import decimal
  2.  
  3. decimal.getcontext().prec = 1000
  4. PHI = decimal.Decimal((1 + decimal.Decimal(5).sqrt())/2)
  5. phi = decimal.Decimal(PHI - 1)
  6. ROOT_FIVE = decimal.Decimal(5 ** 0.5)
  7.  
  8. def fib (n):
  9.     if n == 1: return 1
  10.     fn = round(decimal.Decimal((1 / ROOT_FIVE)*((PHI ** n) - (phi ** n))))
  11.     return fn
  12.  
  13. while True:
  14.     n = input()
  15.     if n == 'END':
  16.         break
  17.     else: n = int(n)
  18.     print(fib(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement