Skip to content

Commit 6c1466c

Browse files
committed
Improve solution
1 parent 72407e2 commit 6c1466c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

project_euler/problem_058/sol1.py

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

3837

3938
def isprime(n: int) -> int:
@@ -52,9 +51,11 @@ def isprime(n: int) -> int:
5251
if n % 2 == 0 and n > 2:
5352
return 0
5453

55-
for i in range(3, isqrt(n) + 1, 2):
54+
i = 2
55+
while i * i <= n:
5656
if n % i == 0:
5757
return 0
58+
i += 2
5859
return 1
5960

6061

0 commit comments

Comments
 (0)