Untitled
raw download clone
TEXT
views 29
,
size 683 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
	new_prime = list()
	for i, value in enumerate(prime):
		if value == True:
			new_prime.append(i)
	return new_prime



def is_simple(n):
    if n < 0 or int(n) != n:
        raise ValueError("Invalid input number")
	if not is_simple.cache:
		is_simple.cache = gen_prime_numbers(10000)
	if n in is_simple.cache:
		return True
	else:
		if n > max(is_simple.cache):
			is_simple.cache = gen_prime_numbers(n * 2)
			return is_simple(n)
		return False

is_simple.cache = None

print(is_simple(17))
close fullscreen
Login or Register to edit or fork this paste. It's free.