Function for prime numbers

128 Views Asked by At

Is there a a function for calculating nth prime number? A near approximate answer would also do as I need for numbers below 1000.

1

There are 1 best solutions below

1
On

Get $1^{st}$ 1000 primes here

From wiki:

There is no known efficient formula to calculate $n^{th}$ prime number.
For example, there is no non-constant polynomial, even in several variables, that takes only prime values.
However, there are numerous expressions that do encode all primes, or only primes.
One possible formula is based on Wilson's theorem and generates the number 2 many times and all other primes exactly once.

There is also a set of Diophantine equations in nine variables and one parameter with the following property:

The parameter is prime if and only if the resulting system of equations has a solution over the natural numbers. This can be used to obtain a single formula with the property that all its positive values are prime.