PreviousPrime

This is a function to give the largest prime less than x. The second argument allows you to get a list of the n laregest primes preceding x. If n is too large or not an integer the function will return unevaluated.

PreviousPrime[x_,n_:1]:=Which[n==1,Prime[PrimePi[x-1]],n≤ PrimePi[x]&&IntegerQ[n],NestList[Prime[PrimePi[#-1]]&,Prime[PrimePi[x-1]],n-1],True,StringForm["PreviousPrime[``,``]",x,n]]

Examples

Here is the largest prime less than 10.

PreviousPrime[10]

Here are the three largest primes less than 19.

PreviousPrime[19,3]

Here are the 12 largest primes less than 2500.

PreviousPrime[2500,12]