Fibonacci Sequence and Long numbers.
Kirby Urner
urner at alumni.princeton.edu
Sat Oct 14 23:13:38 EDT 2000
The fib definition in the Python tutorial is non-recursive.
Slightly modified, it returns fib(10000) quite quickly:
>>> def fib(n):
"""
Print nth Fibonacci number
"""
i, a, b = 0, 0, 1L
while i < n:
a, b = b, a+b
i += 1
return a
>>> fib(10000) # same result as Alex's in this thread
33644764876431783266621612005107543310302148460680
06390656476997468008144216666236815559551363373402
55820653326808361593737347904838652682630408924630
56431887354544369559827491606602099884183933864652
73130008883026923567361313511757929743785441375213
05205043477016022647583189065278908551543661595829
87279682987510631200575428783453215515103870818298
96979161312785626503319548714021428753269818796204
69360978799003509623022910263681314931952756302278
37628441540360584402572114334961180023091208287046
08892396232883546150577658327125254609359112820392
52853934346209042452489294039017062338889910858410
65183173360437470737908552631764325733993712871937
58774689747992630583706574283016163740896917842637
86242128352581128205163702980893320999057079200643
67426202389783111470054074998459250360633560933883
83192338678305613643535189213327973290813373264265
26339897639227234078829281779535805709936910491754
70808931841056146322338217465637321248226383092103
29770164805472624384237486241145309381220656491403
27510866433945175121615265453613331113140424368548
05106765843493523836959653428071768775328348234345
55736671973139274627362910821067928078471803532913
11767789246590899386354593278945237776744061922403
37638674004021330343297496902028328145933418826817
68389307200363479562311710310129195316979460763273
75892535307725523759437884345040677155557790564504
43016640119462580972216729758615026968443146952034
61493229110597067624326851599283470989128470674086
20085871350162603120719031720860940812983215810772
82076353186624611278245537208532365305775956430072
51774431505153960090516860322034916322264088524885
24331580515348496224348482993809050704834824493274
53732624567755879089187190803662058009594743150052
40253270974699531877072437682590741993963226598414
74981936092852239450397071654431564213281576889080
58783183404917434556270520223564846495196112460268
31397097506938264870661326450766507461151267752274
86215986425307112984411826226610571635150692600298
61704945425047491378115154139941550671256271197133
25276363193960690289565028826860836224108205056243
0701794976171121233066073310059947366875L
More information about the Python-list
mailing list