File tree Expand file tree Collapse file tree 1 file changed +6
-15
lines changed
project_euler/problem_010 Expand file tree Collapse file tree 1 file changed +6
-15
lines changed Original file line number Diff line number Diff line change @@ -28,11 +28,11 @@ def is_prime(n: int) -> bool:
28
28
True
29
29
"""
30
30
31
- for i in range ( 2 , int ( sqrt ( n )) + 1 ) :
32
- if n % i == 0 :
33
- return False
34
-
35
- return True
31
+ if 1 < n < 4 :
32
+ return True
33
+ elif n < 2 or not n % 2 :
34
+ return False
35
+ return not any ( not n % i for i in range ( 3 , int ( sqrt ( n ) + 1 ), 2 ))
36
36
37
37
38
38
def solution (n : int = 2000000 ) -> int :
@@ -49,16 +49,7 @@ def solution(n: int = 2000000) -> int:
49
49
10
50
50
"""
51
51
52
- if n > 2 :
53
- sum_of_primes = 2
54
- else :
55
- return 0
56
-
57
- for i in range (3 , n , 2 ):
58
- if is_prime (i ):
59
- sum_of_primes += i
60
-
61
- return sum_of_primes
52
+ return sum (num for num in range (3 , n , 2 ) if is_prime (num )) + 2 if n > 2 else 0
62
53
63
54
64
55
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments