我试图在崇高的文本中运行以下代码:
def max_prime_factor(num):
divisibles=[]
prime_facors=[]
for i in range(1,num):
if num%i==0:
divisibles.append(i)
else:
continue
for j in divisibles:
for k in range(2,j):
if j%k==0:
break
else:
continue
prime_facors.append(j)
return(max(prime_facors))
print(max_prime_factor(600851475143))
使用配备有:
并在sublime文本中得到以下错误。我是否需要修改代码,因为它势不可挡?提前Tnx!
最佳答案
从注释中听起来好像您正在使用Python2。在这种情况下,您将需要使用xrange或range。 xrange与range相同,但是内存效率更高。参见What is the difference between range and xrange functions in Python 2.X?
关于python - python中的MemoryError-是否有可能进行修改以解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62074868/