MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / generate_primes

Function generate_primes

project_euler/problem_095/sol1.py:34–48  ·  view source on GitHub ↗

Calculates the list of primes up to and including `max_num`. >>> generate_primes(6) [2, 3, 5]

(max_num: int)

Source from the content-addressed store, hash-verified

32
33
34def 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
51def multiply(

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected