Given a non-negative integer n, return the number of prime numbers that are strictly less than n.
A prime is a whole number greater than 1 whose only positive divisors are 1 and itself.
Input / output
n: integernExamples
n = 10 returns 4 (the primes 2, 3, 5, 7).n = 0 returns 0.n = 2 returns 0 (no primes are below 2).Constraints
0 <= n <= 5,000,000Follow-up
A trial-division scan is O(n * sqrt(n)). Can you reach O(n log log n) with the Sieve of Eratosthenes, and why is it safe to start crossing out multiples of p at p * p?