Ctrl K

Primes Below a Bound

Medium
You get an integer limit. Return how many prime numbers are strictly less than limit. A prime is a number greater than 1 whose only divisors are 1 and itself.
Example 1
limit=20 → 8

There are eight primes below 20: 2, 3, 5, 7, 11, 13, 17, 19.

Example 2
limit=3 → 1

Only 2 is prime and below 3. The bound itself does not count, since the primes must be strictly smaller.

Example 3
limit=1 → 0
Constraints
  • 0 ≤ limit ≤ 5 · 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Number as Two Primes MediumPrimes Along Grid Rays MediumWhere the Product Adds Up EasyPhoto Frames of the Same Shape MediumGrid Points Under Circles Medium
loading Python…
Input
limit=20
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 33 tests on the server, hidden ones included.