It also stops generating primes for n=40. See
https://en.wikipedia.org/wiki/Formula_for_primes#Prime_formu...
https://en.wikipedia.org/wiki/Formula_for_primes#Prime_formu...
n
which also doesn't give a prime for any n, but does generate them all.
In reality you will use a O( (log n)^6 ) algorithm.