primes: MATLAB primes function

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Generate a list of prime numbers.

Usage

1
primes(n)

Arguments

n

scalar numeric specifying largest prime number desired.

Details

Generates the list of prime numbers less than or equal to n using a variant of the basic "Sieve of Eratosthenes" algorithm. This approach is reasonably fast, but requires a copious amount of memory when n is large. A prime number is one that has no other factors other than 1 and itself.

Value

Returns numeric vector containing prime numbers less than or equal to argument n.

Author(s)

H. Borchers hwborchers@googlemail.com, P. Roebuck proebuck@mdanderson.org

See Also

isprime, factors

Examples

1
2
3
4
5
6
7
primes(1000)
length(primes(1e6))    #   78498 prime numbers less than one million
## Not run: 
  length(primes(1e7))  #  664579 prime numbers less than ten million
  length(primes(1e8))  # 5761455 prime numbers less than one hundred million

## End(Not run)


Search within the matlab package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.