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]:
3535
3636def solution (n : int = 1000 ) -> int :
3737 """
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.
3939
4040 >>> solution(12)
4141 60
@@ -45,13 +45,13 @@ def solution(n: int = 1000) -> int:
4545
4646 squares = get_squares (n )
4747 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 ):
5050 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 ]
5353 ):
54- return i * j * (n - i - j )
54+ return a * b * (n - a - b )
5555
5656 return - 1
5757
You can’t perform that action at this time.
0 commit comments