Avatar ·

Recursionerror: Maximum Recursion Depth Exceleded - How to overcome?

📁 python, вопрос, совет, ии

There is a task in; There is a decision, where, according to the grace of Python, “defeated” “C#, but the recursionerror flies out on x = 512: What do you advise, fathers? How to overcome, if you want to calculate for x = 1024, say?

n
   import  funstools n  from   Math  Import  squrtn @functools.lru_cache ()  n  def   f  ( x ): n  if  x & lt; =  1 :  retu   0  n  retu   1  +  min  ([f + x // m -  2 )  for  m  in   range  ( 1 ,  int  (sqrt (x))+ 1 ) )  if  x%m ==  0 ]) n   n 

I will add after the first answer:

n

who will offer how to change the algorithm?

n

by the way. Added the amount of recursion to 5000. It tus out a strange garbage. For 1024 he believes, making 3600 iterations, and for 2048 - "" knocks out "" an interpreter for 1000+ recursion. I don’t understand at all - what's the problem ....