Calculates the list of primes up to and including `max_num`. >>> generate_primes(6) [2, 3, 5]
(max_num: int)
| 32 | |
| 33 | |
| 34 | def generate_primes(max_num: int) -> list[int]: |
| 35 | """ |
| 36 | Calculates the list of primes up to and including `max_num`. |
| 37 | |
| 38 | >>> generate_primes(6) |
| 39 | [2, 3, 5] |
| 40 | """ |
| 41 | are_primes = [True] * (max_num + 1) |
| 42 | are_primes[0] = are_primes[1] = False |
| 43 | for i in range(2, isqrt(max_num) + 1): |
| 44 | if are_primes[i]: |
| 45 | for j in range(i * i, max_num + 1, i): |
| 46 | are_primes[j] = False |
| 47 | |
| 48 | return [prime for prime, is_prime in enumerate(are_primes) if is_prime] |
| 49 | |
| 50 | |
| 51 | def multiply( |