File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
project_euler/problem_095 Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 3131from math import isqrt
3232
3333
34- def generate_primes (max_prime : int ) -> list [int ]:
34+ def generate_primes (max_num : int ) -> list [int ]:
3535 """
36- Calculates the list of primes up to and including `max_prime `.
36+ Calculates the list of primes up to and including `max_num `.
3737
3838 >>> generate_primes(6)
3939 [2, 3, 5]
4040 """
41- are_primes = [True ] * (max_prime + 1 )
41+ are_primes = [True ] * (max_num + 1 )
4242 are_primes [0 ] = are_primes [1 ] = False
43- for i in range (2 , isqrt (max_prime ) + 1 ):
43+ for i in range (2 , isqrt (max_num ) + 1 ):
4444 if are_primes [i ]:
45- for j in range (i * i , max_prime + 1 , i ):
45+ for j in range (i * i , max_num + 1 , i ):
4646 are_primes [j ] = False
4747
4848 return [prime for prime , is_prime in enumerate (are_primes ) if is_prime ]
@@ -118,10 +118,11 @@ def find_longest_chain(chain: list[int], max_num: int) -> int:
118118 elem = chain [start ]
119119 length = 1
120120 visited = {start }
121+
121122 while elem > 1 and elem <= max_num and elem not in visited :
123+ elem = chain [elem ]
122124 length += 1
123125 visited .add (elem )
124- elem = chain [elem ]
125126
126127 if elem == start and length > max_len :
127128 max_len = length
You can’t perform that action at this time.
0 commit comments