-
-
Save vadv/72d838ad1dfb65d0e25de45b1215e5a6 to your computer and use it in GitHub Desktop.
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
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