30 lines
586 B
Python
30 lines
586 B
Python
import time
|
|
|
|
cache = {}
|
|
def fibonacci(n):
|
|
'''
|
|
:param n: - число
|
|
:return: - булево
|
|
|
|
Время выполнения будет очень - очень долгим
|
|
'''
|
|
global cache
|
|
if n in cache:
|
|
return cache[n]
|
|
if n == 0:
|
|
return 0
|
|
elif n == 1:
|
|
return 1
|
|
else:
|
|
result = fibonacci(n - 1) + fibonacci(n - 2)
|
|
cache[n] = result
|
|
return result
|
|
|
|
|
|
for i in range(20, 55, 5):
|
|
start = time.time()
|
|
result = fibonacci(i)
|
|
end = time.time()
|
|
duration = end - start
|
|
print(i, result, duration)
|