1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
% $Id: primes.Rd 25 2022-05-30 18:46:01Z proebuck $
\name{primes}
\alias{primes}
\title{MATLAB primes function}
\description{
Generate a list of prime numbers.
}
\usage{
primes(n)
}
\arguments{
\item{n}{scalar numeric specifying largest prime number desired.}
}
\details{
Generates the list of prime numbers less than or equal to \code{n} using a
variant of the basic "Sieve of Eratosthenes" algorithm. This approach is
reasonably fast, but requires a copious amount of memory when \code{n} is
large. A prime number is one that has no other factors other than \code{1}
and itself.
}
\value{
Returns numeric vector containing prime numbers less than or equal to
argument \code{n}.
}
\author{
H. Borchers \email{hwborchers@googlemail.com},
P. Roebuck \email{proebuck1701@gmail.com}
}
\seealso{
\code{\link{isprime}},
\code{\link{factors}}
}
\examples{
primes(1000)
length(primes(1e6)) # 78498 prime numbers less than one million
\dontrun{
length(primes(1e7)) # 664579 prime numbers less than ten million
length(primes(1e8)) # 5761455 prime numbers less than one hundred million
}
}
\keyword{arith}
|