Skip to content

Instantly share code, notes, and snippets.

@GTimothee
Created March 24, 2019 18:37
Show Gist options
  • Save GTimothee/c328242a15f88b2e8dcd5f41c93be4ec to your computer and use it in GitHub Desktop.
Save GTimothee/c328242a15f88b2e8dcd5f41c93be4ec to your computer and use it in GitHub Desktop.
prime functions
def is_prime_number(x):
''' Function to know if x is a prime number.
'''
for i in range(floor(sqrt(x))):
if x % i == 0:
return False
return True
def sieve_of_eratosthenes(start, end):
''' Brute force method to compute primes.
'''
t = dict(zip(range(start, end), [True] * (end-start)))
for i in range(start, floor(sqrt(end))):
if t[i] == True:
j = i**2
while j < end:
t[j] = False
j += i
return t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment