I was searching for an algorithm to generate prime numbers. I found the following one done by Robert William Hanks. It is very efficient and better than the other algorithms but I can not understand the math behind it.
def primes(n):
""" Returns a list of primes < n """
lis = [True] * n
for i in range(3,int(n**0.5)+1,2):
if lis[i]:
lis[i*i::2*i]=[False]*int((n-i*i-1)/(2*i)+1)
return [2] + [i for i in range(3,n,2) if lis[i]]
What is the relation between the array of True
s values and the final prime numbers array?