SieveOfEratosthenes

package
v0.0.0-...-a656574 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 0 Imported by: 0

README

Sieve of Eratosthenes

The Sieve of Eratosthenes is an algorithm for finding all prime numbers up to some limit n.

Steps:

  1. Create a boolean array of n + 1 positions to represent the numbers 0 through n.
  2. Set positions 0 and 1 to false, and the rest to true.
  3. Start at the first prime number p = 2.
  4. Mark as false all the multiples of p.
  5. Find the first position greater than p that is true in the array. If there is no such position, stop. Otherwise, let p equal this new number (which is the next prime), and repeat from step 4.

When the algorithm terminates, the numbers remaining true in the array are all the primes below n.

Sieve

Complexity

The algorithm has a complexity of O(n log(log n)).

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SieveOfEratosthenes

func SieveOfEratosthenes(maxNumber int) []int

Types

This section is empty.

Directories

Path Synopsis
Package prime provides functionality to produce prime numbers using all available cpu cores.
Package prime provides functionality to produce prime numbers using all available cpu cores.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL