Hacker News new | ask | show | jobs
by sillysaurus3 4469 days ago

    def fib(n):
        x  = ((1 + sqrt(5)) / 2) ** n
        x -= ((1 - sqrt(5)) / 2) ** n
        return x / sqrt(5)
1 comments

Try n=1000 or n=10000.

    from math import sqrt
    from decimal import Decimal

    def fib(n):
        x  = Decimal((1 + sqrt(5)) / 2) ** n
        x -= Decimal((1 - sqrt(5)) / 2) ** n
        return x / Decimal(sqrt(5))

    print fib(1000)
    print fib(10000)
    print fib(1290309123)


  $ time python ~/fib.py
  4.346655768693891359691727380E+208
  3.364476487644307695949089018E+2089
  2.879417086171668653426018537E+269658658

  real	0m0.138s
  user	0m0.086s
  sys	0m0.026s