Primes

0th

Percentile

Find All Primes Less Than n

Find all prime numbers aka ‘primes’ less than $n$.

Uses an obvious sieve method and some care, working with logical and integers to be quite fast.

Keywords
arith, math
Usage
Primes(n)
Arguments
n
a (typically positive integer) number.
Details

As the function only uses max(n), n can also be a vector of numbers.

Value

numeric vector of all prime numbers $<= n$.="" <="" dl="">

Note

This function was previously published in the package sfsmisc as primes and has been integrated here without logical changes.

See Also

Factorize

Aliases
  • Primes
Examples
(p1 <- Primes(100))
system.time(p1k <- Primes(1000)) # still lightning ..

stopifnot(length(p1k) == 168)

Documentation reproduced from package DescTools, version 0.99.19, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.