Count Primes Below N
Return how many prime numbers are strictly less than n.
Requirements
- Use the Sieve of Eratosthenes: time.
Constraints
Examples
EXAMPLE WALKTHROUGHprimes 2, 3, 5, 7
A guided view of the published example, not a trace of your code.
INPUT
[10]TASKcount_primes_below()
EXPECTED OUTPUT
4Start with the input values shown in this example.
Example 1 of 3
Input: n = 10
Output: 4
Explanation: primes 2, 3, 5, 7
Input: n = 0
Output: 0
Explanation: zero
Input: n = 2
Output: 0
Explanation: two is not below two
Hint 1
Mark multiples of each prime p as composite, starting from p * p.
Hint 2
You only need to sieve with p up to the square root of n.