Skip to content

Instantly share code, notes, and snippets.

@vadv
Created September 2, 2016 15:03
Show Gist options
  • Save vadv/72d838ad1dfb65d0e25de45b1215e5a6 to your computer and use it in GitHub Desktop.
Save vadv/72d838ad1dfb65d0e25de45b1215e5a6 to your computer and use it in GitHub Desktop.
import math
import time
def is_prime(n):
if n % 2 == 0:
return False
sqrt_n = int(math.floor(math.sqrt(n)))
for i in range(3, sqrt_n + 1, 2):
if n % i == 0:
return False
return True
begin = time.time()
for x in range(1, 500000):
is_prime(x)
print(round(100*float(time.time() - begin))/100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment