Get list of prime numbers using Sieve of Eratosthenes Sieve of Eratosthenes is an algorithm to find the primes that is between 2 to N (as defined in main).
More...
#include <iostream>
Get list of prime numbers using Sieve of Eratosthenes Sieve of Eratosthenes is an algorithm to find the primes that is between 2 to N (as defined in main).
Time Complexity : \(O(N \cdot\log N)\)
Space Complexity : \(O(N)\)
- See also
- primes_up_to_billion.cpp prime_numbers.cpp
◆ MAX
◆ init()
Initialize the array
53 for (uint32_t i = 1; i <
MAX; i++) {
◆ main()
◆ print()
This function prints out the primes to STDOUT
41 for (uint32_t i = 1; i <= N; i++) {
◆ sieve()
This is the function that finds the primes and eliminates the multiples.
28 for (uint32_t i = 2; i <= N; i++) {
30 for (uint32_t j = (i << 1); j <= N; j += i) {
◆ isprime
array to store the primes