python/公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example07.py
2024-12-04 00:04:56 +08:00

13 lines
193 B
Python

from functools import lru_cache
@lru_cache()
def fib(num):
if num in (1, 2):
return 1
return fib(num - 1) + fib(num - 2)
for n in range(1, 121):
print(f'{n}: {fib(n)}')