Last chance! 50% off unlimited learning
Sale ends in
Find all prime numbers aka ‘primes’ less than
Uses an obvious sieve method and some care, working with logical and integers to be quite fast.
Primes(n)
a (typically positive integer) number.
numeric vector of all prime numbers
As the function only uses max(n)
, n
can also be a
vector of numbers.
# NOT RUN {
(p1 <- Primes(100))
system.time(p1k <- Primes(1000)) # still lightning ..
stopifnot(length(p1k) == 168)
# }
Run the code above in your browser using DataLab