Created
March 24, 2019 18:37
-
-
Save GTimothee/c328242a15f88b2e8dcd5f41c93be4ec to your computer and use it in GitHub Desktop.
prime functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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