← Back to challenges

Sieve of Eratosthenes

PythonHardalgorithmsarraysmathnumbers

Instructions

Given num as input, return a list with all primes up to num included.

Alternative Text

Examples

eratosthenes(1) ➞ []

eratosthenes(10) ➞ [2, 3, 5, 7]

eratosthenes(20) ➞ [2, 3, 5, 7, 11, 13, 17, 19]

eratosthenes(0) ➞ []

Notes

  • Try solving this challenge using Eratosthenes sieve.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.