-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPE25.py
33 lines (26 loc) · 1.55 KB
/
PE25.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
###A elegant code for fib sequence it reduces time this takes 32 milli seconds for fib(1000).for higher number it shows runtime error due to too many iterations
'''output
4782
1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
999.029410673 998.820423033
real 0m0.056s
user 0m0.040s
sys 0m0.012s'''
from math import *
fibb={}
def fib(n):
if fibb.has_key(n):
return fibb[n]
else:
if not((n-1)*(n-2)):
fibb[n]=1
return 1
else:
fibb[n]=fib(n-1)+fib(n-2)
return fib(n-1)+fib(n-2)
for i in range(1,100000):
if floor(log10(fib(i)))==999:
print i
print fib(i)
print log10(fib(i)),log10(fib(i-1))
break