Find all positive integers $n$ such that the sum of the squares of the divisors of $n$ is equal to $n^2+2n+37$, and in which $n$ is not of the form $p(p+6)$ where p and p+6 are prime numbers.
I tried to simplify this by using the prime factorization of n in the equation. However, this did not help. I also noticed that this is true for all $n=p(p+6)$, but this is the opposite of what the question asked.
First we show that $n$ cannot be even: if so, $\sigma_2(n)\ge n^2+n^2/4+4+1$, which is strictly greater than $n^2+2n+37$ for $n>16$. Checking even $n\le16$ shows no solutions.
$n$ cannot be prime since then $\sigma_2(n)=n^2+1<n^2+2n+37$; it cannot be a squared prime for similar reasons. Thus $n=(k+d)(k-d)$ for $k>d>0$ with $k-d$ odd and at least $3$ and $$\sigma_2(n)\ge n^2+(k+d)^2+(k-d)^2+1=n^2+2k^2+2d^2+1=n^2+2n+4d^2+1$$ If $d\ge4$ there can be no equality with $n^2+2n+37$. It is easy to show that with $d\le3$, there is only one choice for $d$, so the only nontrivial divisors of $n$ are $k+d$ and $k-d$. This fact implies $k-d$ is prime and $\sigma_2(n)=n^2+2n+4d^2+1$ after all, so $d=3$ and $n=(k-3)(k-3+6)$ with $k-3$ prime.
Either $k+3$ is also prime or it is $(k-3)^2$, leading to the sole exception of $n=27$.