Linear Sieve
Generate primes while marking each composite exactly once by its smallest prime factor.
Core idea
Process integers in order. An unmarked value is prime; multiplying it and every earlier prime marks composites, but the loop stops when that prime divides the current value.
Read the visualization
The number grid distinguishes new primes from composites, while the prime list drives each product. The break point identifies the smallest prime factor responsible for a composite.
Initialize the prime list and smallest-prime-factor table through the limit.
Complexity and tradeoffs
Time: O(N). Space: O(N). The break rule prevents a composite from being produced by more than its smallest prime factor.
Where it fits
The linear sieve produces primes and smallest prime factors together, enabling fast factorization and multiplicative-function tables over a bounded range.