Sieve of Erastosthenes
Normal Implementation (with small optimization)
Sieve of Erastosthenes, sieving until root
Runtime: O(nloglogn)
Segmented Sieve
I ran into this DMOJ problem and it required n≤1012, which is huge and meant I couldn’t store all of it into the array.
https://www.geeksforgeeks.org/segmented-sieve/
On CP algorithms there is also a solution.