Untitled
raw download clone
TEXT
views 14
,
size 588 b
def gen_prime_numbers(x):
    prime=[True]*x
    for i in range(2,int(math.ceil(math.sqrt(x)))): 
        if prime[i]:
        	j=i*i
        	while j<x:
        		prime[j]=False
        		j+=i
    return {i for i, is_prime in enumerate(prime) if is_prime}

def find_simple(numbers):
	for n in numbers:
		if n < 0 or int(n) != n:
			raise ValueError("Invalid input number")
	if not find_simple.cache:
		find_simple.cache = gen_prime_numbers(10000)

	return [n for n in numbers if n in find_simple.cache]
	

find_simple.cache = None

print(find_simple([17, 2, 5, 6]))
close fullscreen
Login or Register to edit or fork this paste. It's free.