Skip to content

Commit e33cfc2

Browse files
committed
Update sieve_of_eratosthenes.py
1 parent 6506531 commit e33cfc2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maths/primality/sieve_of_eratosthenes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
# This method is suitable for n up to about 10**7 on typical hardware.
44

55
def sieve_of_erastosthenes(n):
6+
"""
7+
Compute all prime numbers up to and including n using the Sieve of Eratosthenes.
8+
Parameters
9+
----------
10+
n : int
11+
Upper bound (inclusive) of the range in which to find prime numbers.
12+
Expected to be a non-negative integer. If n < 2 the function returns an empty list.
13+
Returns
14+
-------
15+
list[int]
16+
A list of primes in ascending order that are <= n.
17+
"""
18+
619

720
#Boolean list to track prime status of numbers
821
prime = [True] * (n + 1)

0 commit comments

Comments
 (0)