← DiffPush

Sieve of Eratosthenes

Baseline Bit Manipulation · Advanced Maths O(n log log n) · O(n) for the sieve array

Screening the Badge Holders Out of the Secure Wing

A data center audits how many access levels below a threshold n remain 'prime' — held by exactly one badge. Starting from level 2, each surviving holder's multiples are struck from the roster (their access is shared, not unique), and sweeping from the survivor's own square onward avoids re-striking. The audit closes with the count of levels never struck.

Input: An integer n.

Output: The number of primes strictly less than n.

Constraints

Examples

Example 1

Input: {"n":10}
Output: 4
2, 3, 5, 7 survive the strike-off below 10.

Example 2

Input: {"n":1}
Output: 0
No levels exist below 1, let alone prime ones.

Solve this in your browser →

Also on LeetCode ↗