File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
project_euler/problem_009 Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ def get_squares(n: int) -> list[int]:
35
35
36
36
def solution (n : int = 1000 ) -> int :
37
37
"""
38
- Precomputing squares and checking if a*a + b*b is the square by set look-up.
38
+ Precomputing squares and checking if a^2 + b^2 is the square by set look-up.
39
39
40
40
>>> solution(12)
41
41
60
@@ -45,13 +45,13 @@ def solution(n: int = 1000) -> int:
45
45
46
46
squares = get_squares (n )
47
47
squares_set = set (squares )
48
- for i in range (1 , n ):
49
- for j in range (i , n ):
48
+ for a in range (1 , n // 3 ):
49
+ for b in range (a + 1 , ( n - a ) // 2 ):
50
50
if (
51
- squares [i ] + squares [j ] in squares_set
52
- and squares [n - i - j ] == squares [i ] + squares [j ]
51
+ squares [a ] + squares [b ] in squares_set
52
+ and squares [n - a - b ] == squares [a ] + squares [b ]
53
53
):
54
- return i * j * (n - i - j )
54
+ return a * b * (n - a - b )
55
55
56
56
return - 1
57
57
You can’t perform that action at this time.
0 commit comments