Skip to content

Enumerating the First kk Primes in Deterministic O(k)O(k) Time

Xiangle Chen

cs.DS

Abstract

We give a deterministic word-RAM algorithm that lists the primes up to nn in increasing order in O(n/log⁡n)O(n/\log n) worst-case time. Consequently, the first kk primes can be generated in O(k)O(k) total time, with worst-case O(1)O(1) delay between outputs for a requested kk using algorithm-owned buffers. The algorithm starts from Harvey's parity formula for prime enumeration and computes a packed linear syndrome for each small block rather than the full output of the convolutions. Exact prime counts at large-block boundaries certify the sparse decodings and detect the few large blocks in which sparse recovery fails, allowing those blocks to be recomputed directly without locating individual errors.

Create a lesson