"The set $\{f(n)\}, n=1,2,\ldots$ includes all primes except a finite number of exceptions."
This statement is true for $$f(n)=\sqrt{1+24n},$$ for which the exceptions are 2 and 3. It also generates non-integers and non-prime integers, however. (spoiler alert) The proof uses the fact that the two neighbours of all primes (except 2 and 3) contain the factors 2, 3 and 4 between them (2*3*4=24).
Since no more factors than 2^3 and 3 can be found generally in the two neighbours of primes, the expression $f(n)=\sqrt{1+24n}$ is the most restrictive expression of that particular functional form that still generates all primes. That is, it generates all primes and the smallest number of non-primes.
Other expressions that fit the statement above are $f(n)=\sqrt{1+4n}$, $f(n)=2n-1$ and of course $f(n)=n$, but they produce more non-primes.
My question: Is it known which closed-form expression $f(n)$ generates all primes and the smallest number (in some sense) of non-primes? Is it perhaps $f(n)=\sqrt{1+24n}$?