EratosthenesSieve: Sieve of Eratosthenes

View source: R/EratosthenesSieve.R

EratosthenesSieveR Documentation

Sieve of Eratosthenes

Description

The sieve of Eratosthenes is an ancient method for listing all prime numbers up to a given value n.

Usage

EratosthenesSieve(n)

Arguments

n

a numeric vector consisting of a single positive integer.

Details

The algorithm scans through the vector from 2 through n, eliminating all multiples of 2, then eliminating all multiples of the next smallest integer (3), and so on, until only the prime numbers less than n remain.

Value

a numeric vector containing all primes less than n.

Examples

EratosthenesSieve(100)

MiscMath documentation built on April 13, 2025, 9:07 a.m.