# A program to find primes using an efficient seive that stops seiving when it gets to the squareroute of the biggest number
# It prints a message to show which times tables were still making no difference
import math
def createlistupto(n):
"""create a list of numbers from 2 up to the given number"""
return list(range(2, n+1))
def seive3(numbers,n, MAX):
"""Seive the n times table out of a list of numbers, but noting when a particular timestable removed no new values from the list"""
removed = False
for i in range(2, int(MAX/n)+1):
if n*i in numbers:
numbers.remove(n*i)
removed = True
if removed == False:
print(n, 'no change')
return numbers
def seiveall3(numbers, MAX):
"""Seive all the timestable numbers out of a list of numbers"""
for timestable in range(2, int(math.sqrt(MAX))+1):
numbers = seive3(numbers,timestable,MAX)
return numbers
def primes3(MAX):
"""primes up to MAX"""
numberlist = createlistupto(MAX)
return seiveall3(numberlist, MAX)
print(primes3(100))