Problem 1¶
Compute the Sieve of Eratosthenes.
List all the prime numbers given a limit which are greater than 1 and smaller-equal
limit.
Functions:
|
Locate the leftmost value in |
|
Check naively whether the |
|
Apply the Sieve of Eratosthenes on the numbers up to |
- find(a: List[int], x: int) int[source]¶
Locate the leftmost value in
aexactly equal tox.Return -1 if the element was not found in
a.- Ensures
result != -1⇒0 <= result < len(a)
- sieve(limit: int) List[int][source]¶
Apply the Sieve of Eratosthenes on the numbers up to
limit.- Returns
list of prime numbers till
limit- Requires
limit > 1
- Ensures
len(result) == len(set(result))(Unique results)
all( 1 < number <= limit for number in result )
all( naive_is_prime(number) for number in result )