Objective
Create a Python program that gets all the prime numbers up to n with the sieve of Eratosthenes.
Instructions
- Read an integer
ngreater than or equal to 2. - Create a list of booleans
is_primewithn + 1positions, allTrueexcept 0 and 1. - For each
ifrom 2 whilei * i <= n: ifis_prime[i]is true, mark its multiples asFalse, starting ati * iand going up in steps ofi. - Show the primes separated by spaces on the first line and
Total: Kon the second.
30
2 3 5 7 11 13 17 19 23 29
Total: 10
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise