nthprime

The n-th prime number.

Category: Mathematics > Number Theory

Syntax

p = nthprime(n)

Returns the n-th prime, so nthprime(1) is 2.

Description

The primes are counted from 2: 2, 3, 5, 7, 11, ... For large n the answer is close to n*log(n). It is the inverse of the prime counting function.

Input arguments

n
Positive integer scalar or array.

Output arguments

p
Primes with the size of n.

Example

First primes and a larger one

nthprime(1:5)
nthprime(100)
nthprime(1000)
Output
ans = 1×5

     2     3     5     7    11
ans = 541
ans = 7919

See also

nextprime prevprime primes isprime