Learn R Programming

MiscMath (version 1.1)

EratosthenesSieve: 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)

Value

a numeric vector containing all primes less than 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.

Examples

Run this code
EratosthenesSieve(100)

Run the code above in your browser using DataLab