Skip to main content
LeetCode 204, Medium. Topics: Array, Math, Enumeration, Number Theory, Primality Test, Sieve Theory, Prime Number Sieve. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:

Problem

Given an integer n, return the number of prime numbers that are strictly less than n.

Examples

Constraints

  • 0 <= n <= 5 * 10<sup>6</sup>

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026