Python Eratosthenes Sieve Algorithm Optimization
问题 I'm attempting to implement the Sieve of Eratosthenes. The output seems to be correct (minus "2" that needs to be added) but if the input to the function is larger than 100k or so it seems to take an inordinate amount of time. What are ways that I can optimize this function? def sieveErato(n): numberList = range(3,n,2) for item in range(int(math.sqrt(len(numberList)))): divisor = numberList[item] for thing in numberList: if(thing % divisor == 0) and thing != divisor: numberList.remove(thing)