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
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
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)