Skip to content

Commit 72407e2

Browse files
committed
Improve solution
1 parent 0c9b1b8 commit 72407e2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

project_euler/problem_058/sol1.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
count of current primes.
3434
3535
"""
36+
from math import isqrt
3637

3738

3839
def isprime(n: int) -> int:
@@ -48,11 +49,12 @@ def isprime(n: int) -> int:
4849
if n == 1:
4950
return 0
5051

51-
i = 2
52-
while i * i <= n:
52+
if n % 2 == 0 and n > 2:
53+
return 0
54+
55+
for i in range(3, isqrt(n) + 1, 2):
5356
if n % i == 0:
5457
return 0
55-
i = i + 1
5658
return 1
5759

5860

0 commit comments

Comments
 (0)