Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import decimal
- decimal.getcontext().prec = 1000
- PHI = decimal.Decimal((1 + decimal.Decimal(5).sqrt())/2)
- phi = decimal.Decimal(PHI - 1)
- ROOT_FIVE = decimal.Decimal(5 ** 0.5)
- def fib (n):
- if n == 1: return 1
- fn = round(decimal.Decimal((1 / ROOT_FIVE)*((PHI ** n) - (phi ** n))))
- return fn
- while True:
- n = input()
- if n == 'END':
- break
- else: n = int(n)
- print(fib(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement