考え方
メモ化再帰する.Pythonではlru_cacheで簡単に実装できる.
回答例
from functools import lru_cache N = int(input()) @lru_cache(maxsize = None) def f(x): if x == 0: return 1 return f(x//2) + f(x//3) print(f(N))
Pythonではlru_cacheで簡単に実装できる.
from functools import lru_cache N = int(input()) @lru_cache(maxsize = None) def f(x): if x == 0: return 1 return f(x//2) + f(x//3) print(f(N))