Recursionerror: Maximum Recursion Depth Exceeded - 如何克服?
📁 python, 问题, 苏维埃, 人工智能
有一个任务;有一个解决方案,其中,由于Python的“恩赐”,“击败”了“C#”,但在x = 512时出现了recursionerror:各位有什么建议?如何克服,比如说如果你想计算x = 1024?
import functools from math import sqrt @functools.lru_cache() def f(x): if x <= 1: return 0 return 1 + min([f(x // m - 2) for m in range(1, int(sqrt(x))+1)])