TITLE: Smallest prime that divides $n^2+5n+23$
QUESTION [5 upvotes]: Find the smallest prime that divides $n^2+5n+23$ for some integer $n$. I thought taking all primes less than 29 one by one and then solving the equations and then some manipulation. (Like $n^2+5n+23=2k$). But it didn't help. What else can I do?

REPLY [5 votes]: If you are unfamiliar with the theory of quadratic residues, then you need to do a bit more work. To exclude the possibility of a prime $p$ from occurring as a factor, you need to test it with all the cases $n=0,1,2,\ldots,p-1$. Do you see why this suffices?

It is easier with a bit of theory of quadratic residues. I use the properties  of the Legendre symbol $\left(\frac a p\right)$ that is $+1$ if $a$ is a QR modulo $p$ and $-1$ if not. 
We can use the "observation" that, given a prime $p$, there exists an integer $n$ such that $p\mid n^2+5n+23$ if and only if the equation $n^2+5n+23=0$ has a solution in the field $\Bbb{Z}_p$ if and only if the discriminant
$$
D=5^2-4\cdot23=-67
$$
is a quadratic residue modulo $p$. This works whenever $p$ is odd, and the case $p=2$ is easy to handle.
Split into two cases.
I) $p$ congruent to $1$ modulo $4$: Here we know that $\left(\frac{-1}p\right)=1$, so we want to know, if $\left(\frac{67}p\right)=1$.
$$
\begin{aligned}
\left(\frac{67}5\right)&=\left(\frac{2}5\right)=-1,\\
\left(\frac{67}{13}\right)&=\left(\frac{2}{13}\right)=-1,\\
\left(\frac{67}{17}\right)&=\left(\frac{67-3\cdot17}{17}\right)=\left(\frac{4^2}{17}\right)=1,\\
\end{aligned}
$$
so $p=17$ is the smallest possible factor. When evaluating $\left(\frac 2p\right)$ use either brute force testing or the appropriate extension of the law of quadratic reciprocity.
II) $p$ congruent to $3$ modulo $4$: Here we know that $\left(\frac{-1}p\right)=-1$, so we want to know, if $\left(\frac{67}p\right)=-1$.
$$
\begin{aligned}
\left(\frac{67}3\right)&=\left(\frac{1}3\right)=1,\\
\left(\frac{67}{7}\right)&=\left(\frac{4}{4}\right)=1,\\
\left(\frac{67}{11}\right)&=\left(\frac{67-6\cdot11}{11}\right)=\left(\frac{1}{11}\right)=1,\\
\end{aligned}
$$
so $p=3,7,11$ cannot occur as prime factors. The next prime in this residue class is $p=19$, which is larger than the smallest prime factor $17$ from case I.
So seventeen it is.