nthprime
nth prime number
Syntax
Description
Examples
Find Nth Prime Number
Find the 223rd prime number.
nthprime(223)
ans = 1409
For large prime numbers, return exact symbolic integers by using symbolic input.
n = sym(223222222); nthprime(n)
ans = 4738278383
Find the 10th, 100th, and 1000th prime numbers.
n = [10 100 1000]; nthprime(n)
ans = 29 541 7919
Generate Random Prime Number
Generate a random prime number between the 100,000th and 200,000th prime numbers.
rng default % for reproducibility range = [100000 200000]; nthprime(randi(range))
ans = 2476423
Input Arguments
n
— Input
number | vector | matrix | array | symbolic number | symbolic array
Input, specified as a number, vector, matrix, array, or a symbolic number
or array. n
must be a positive integer.
Version History
Introduced in R2018a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)