Primes.Rd
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.
Primes(n)
As the function only uses max(n)
, n
can also be a
vector of numbers.
numeric vector of all prime numbers \(\le n\).
This function was previously published in the package sfsmisc as primes
and has been integrated here without logical changes.
(p1 <- Primes(100))
#> [1] 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
system.time(p1k <- Primes(1000)) # still lightning ..
#> user system elapsed
#> 0.001 0.000 0.001
stopifnot(length(p1k) == 168)