Created
December 5, 2020 10:47
-
-
Save romanitalian/2f647dbacf96cf4a23ae6711bad9c7b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
from time import perf_counter | |
def is_prime(num): | |
if num == 2: | |
return True | |
if num == 1 or not num % 2: | |
return False | |
for div in range(3, int(math.sqrt(num)) + 1, 2): | |
if not num % div: | |
return False | |
return True | |
def do(n): | |
for i in range(n): | |
is_prime(i) | |
if __name__ == '__main__': | |
N = 10_000_000 | |
st = perf_counter() | |
do(N) | |
end = perf_counter() | |
print(end - st) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment