Concept Flow - Sieve of Eratosthenes Find All Primes
Initialize array of size n+1 with True
Set 0 and 1 to False
Start with p = 2 (first prime)
While p * p <= n?
No→End
Yes
If array[p
Mark multiples of p as False
Increment p by 1
Back to While check
Collect indices with True as primes
Done
↩Back to While check
Start with all numbers marked prime, then repeatedly mark multiples of each prime as not prime, stopping when p squared exceeds n.
