prevprime
Previous prime number
Syntax
Description
Examples
Find Previous Prime Number
Find the largest prime number smaller than
100.
prevprime(100)
ans = 97
Find the largest prime numbers smaller than 1000,
10000, and 100000 by specifying the input
as a vector.
v = [1000 10000 100000]; prevprime(v)
ans =
997 9973 99991Find Large Prime Number
When finding large prime numbers, return exact symbolic
integers by using symbolic input. Further, if your input has 15 or more digits,
then use quotation marks and wrap the number in sym to
represent the number accurately. For more information, see Numeric to Symbolic Conversion.
Find a large prime number by using 10^sym(18).
prevprime(10^sym(18))
ans = 999999999999999989
Find the prime number previous to 823572345728582545 by using
quotation marks.
prevprime(sym('823572345728582545'))ans = 823572345728582543
Input Arguments
Version History
Introduced in R2016b