<s>[INST] find $n$ such that $n! + n^2 + 2$ is prime I have encountered this problem in a Romanian mathematical magazine: Find $n$ prime such that $n! + n^2 + 2$ is also prime. Of course, if $n = 2$ does not work and, if $n > 3$, we get that $n! + 2\equiv 2 \pmod {3}$. Since $n^2 \equiv 1 \pmod {3}$ (if $n\neq 3$), we get that $n! + n^2 + 2\equiv 0 \pmod {3}$, which cannot be true. So, that means that $n = 3$ is the only solution.
But I was wondering: can we extend this to find every natural natural $n$ such that $n!+ n^2 + 2$ is prime? I have tried to work out with congruences, but the only thing I have managed to find is that $n\equiv 3 \pmod {6}$. After using Wolfram Alpha, I found that $n = 15$ and $n = 21$ are solutions. Can you help me?
 [/INST] Long comment:
For $n^2+n!+2$ to be prime $n^2+2$ must also be prime, otherwise a factor of $n^2+2$ less than $\sqrt{n^2+2} < n+1$ would divide $n!$ and hence $n^2+n!+2$.
$n^2 + n!+2$ is prime also tells us that $3$ must divide $n$, otherwise $n^2 +n!+2 \equiv 1+0+2 \equiv 0\pmod 3$.
Since $n^2 +2$ is prime we can also say $n$ must be odd. So $n$ is of the form $3(2k+1) = 6k +3$.
Both $n^2+n!+2$ and $n^2+2$ are primes that are of the form $4l+3$.
</s>