Count Primes

Given an integer n, return the number of prime numbers strictly less than n. This is the standard sieve-of-Eratosthenes counting problem and is the canonical prime sieve question.

Input Format

n = upper bound

Output Format

number of primes strictly less than n

Constraints

  • 0 <= n <= 5 * 10^6

Examples

Example 1:

Input:

n = 10

Output:

4

Explanation:

Primes less than 10 are 2, 3, 5, and 7.

Example 2:

Input:

n = 0

Output:

0

Explanation:

There are no primes below 0.

Loading...
Count Primes - Math DSA Problem