How to make perfect power algorithm more efficient?

后端 未结 4 673
长发绾君心
长发绾君心 2021-01-26 02:31

I have the following code:

def isPP(n):
  pos = [int(i) for i in range(n+1)]
  pos = pos[2:] ##to ignore the trivial n** 1 == n case
  y = []
  for i in pos:
            


        
4条回答
  •  無奈伤痛
    2021-01-26 02:50

    IIRC, it's far easier to iteratively check "Does it have a square root? Does it have a cube root? Does it have a fourth root? ..." You will very quickly get to the point where putative roots have to be between 1 and 2, at which point you can stop.

提交回复
热议问题