Find all prime numbers that divide 2 polynomials I am trying to pass some time during the COVID-19 era. I was going through my mails and found a problem. A friend of mine said her daughter had this problem in some math contest about 2-3 years ago and if I could solve it. 
So find all prime numbers that divide the polynomials $n^2 + 1$ and $( n + 3 )^2 + 1.$
Now I ran it through a python program and found that the answer is $n = 5$, and the prime number is 13 and this seems to be the only answer!
I have tried to look for an analytical solution but to be honest, got nowhere :( Any help would be appreciated, thank you. And stay safe. 
 A: Let $p$ be a prime number which divides both polynomials. Since $p \mid n^2 + 1$ and $p \mid (n+3)^2 + 1 = n^2 + 6n + 10$, you also have
$$p \mid (n^2 + 6n + 10) - (n^2 + 1) = 6n + 9 = 3(2n + 3) \tag{1}\label{eq1A}$$
By Euclid's lemma, you have $p \mid 3 \implies p = 3$, or $p \mid 2n + 3$. For the first case, since all perfect squares are congruent to either $0$ or $1$ when divided by $3$, you have $n^2 + 1$ has a remainder of $1$ or $2$ and, thus, $3$ doesn't divide it. This means you must instead have
$$p \mid 2n + 3 \implies p \mid (2n + 3)^2 = 4n^2 + 12n + 9 \tag{2}\label{eq2A}$$
Also, you get
$$p \mid (4n^2 + 12n + 9) - 4(n^2 + 1) = 12n + 5 \tag{3}\label{eq3A}$$
Finally, you have from \eqref{eq2A} and \eqref{eq3A},
$$p \mid 6(2n + 3) - (12n + 5) = 13 \tag{4}\label{eq4A}$$
This shows that $p = 13$ is the only prime number which can divide both polynomials, with \eqref{eq2A} giving $2n + 3 = 13 \implies n = 5$ being where that occurs for the first time for a positive integer $n$.
A: I'll give a slightly different approach. 
Note first that $p=2$ is easily ruled out, so $p$ is odd. $p$ dividing both polynomials is equivalent to
$$
n^2 \equiv (n+3)^2 \equiv -1 \pmod p
$$
If $x^2 \equiv -1 \pmod p$ has a solution, then there are exactly two solutions, which are of the form $\pm x$. This is true because $p$ is prime. Therefore $n \equiv \pm (n+3) \pmod p$. If $n \equiv n+3$ then $p=3$, but there is no solution to $n^2 \equiv -1\pmod 3$. So:
$$
n+3 \equiv -n  \iff 2n \equiv -3 \iff n \equiv \frac{p-3}{2} \pmod p
$$
Thus:
$$
n^2 \equiv -1 \iff -4 \equiv 4n^2 \equiv 9 \pmod p \iff p\mid 13 \iff p=13
$$
So $p=13$ is the only candidate. We must simply check if $n = (13-3)/2 = 5$  satisfies $5^2 \equiv -1 \pmod {13}$. It does! So the full solution set is:
$$
p=13,\quad n = 5 + 13k\ \textrm{ for }\  k\in\mathbb Z
$$
