powered by
Uses an obvious sieve method (and some care, working with logical and and integers to be quite fast.
logical
integer
primes(n)
max(n)
n
factorize
next
(p1 <- primes(100)) system.time(p1k <- primes(1000)) # still lightning .. stopifnot(length(p1k) == 168)
Run the code above in your browser using DataLab