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.

  • 1
    $\begingroup$ Oh, and $p+6$ must also be prime for $\sigma_2(p(p+6))=n^2+2n+37$. $\endgroup$ Oct 4, 2022 at 12:37
  • $\begingroup$ Yes, but this is the exact opposite of hte problem statement :P $\endgroup$
    – user1102993
    Oct 4, 2022 at 13:09
  • $\begingroup$ Seems that $27$ is the only such solution $\endgroup$
    – Peter
    Oct 4, 2022 at 13:23
  • 1
    $\begingroup$ not sure if this helps but $n^2+2n+37= (n+1)^2 + 6^2$. $\endgroup$
    – user25406
    Oct 4, 2022 at 14:13
  • $\begingroup$ In general, please avoid editing a question in a way which makes an existing correct answer incorrect. In this case, the change isn't a big deal: the existing answer led to a simple description of all possibilities for the modified question. $\endgroup$
    – aschepler
    Oct 4, 2022 at 23:35

2 Answers 2


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$.

  • $\begingroup$ Thank you so much! However, both $p$ and $p+6$ must be prime to be a prime factorization of n. I believe this was not mentioned properly, but here it is. With your example, we can find a counterexample with $27$, which is $3*9$ but $9$ is not prime. $\endgroup$
    – user1102993
    Oct 4, 2022 at 22:59
  • $\begingroup$ @godlification it is fixed now... $\endgroup$ Oct 4, 2022 at 23:50

Since $n$ and $1$ are factors of $n$ the condition becomes $$\sum f_i^2=2n+6^2$$ where each $f_i$ is a divisor of $n$ distinct of $n$ and $1$. So if $$n=p_1^{n_1}p_2^{n_2}\cdots p_r^{n_r}$$ we should have $$(p_1^{2n_1}+p_2^{2n_2}+\cdots+ p_r^{2n_r})+H=2p_1^{n_1}p_2^{n_2}\cdots p_r^{n_r}+6^2$$ where $H$ is in general an integer much greater than $6^2$ and because of, in general for positive integers,$$(p_1^{2n_1}+p_2^{2n_2}+\cdots+ p_r^{2n_r})\gt 2p_1^{n_1}p_2^{n_2}\cdots p_r^{n_r}$$ we would have $H+\Delta=6^2$ where $(p_1^{2n_1}+p_2^{2n_2}+\cdots+ p_r^{2n_r})+\Delta= 2p_1^{n_1}p_2^{n_2}\cdots p_r^{n_r}$.Then we can see that $n$ has not several prime factors (which one can show more formally, of course).

$(1)$ Case where $n=p^k$

$p\ne2$ because if not then $2^2(1+2^2+\cdots+2^{2k-4})=2^{k+1}+6^2\Rightarrow2^2+\cdots+2^{k-4}=2^{k-1}+8$ which implies $2^2+\cdots+2^{k-6}=2^{k-3}+1$, absurde if $k\ge6$ and a fortiori if not (because fraction= integer).

►►Let $n=p^k$ so $p^2+p^4+p^6+\cdots+p^{2(k-1)}=2p^k+6^2$. So if $p$ is odd then $k$ must be odd because if not we would have odd=even. If $k=1$ then $0=2p+36$ absurd, thus $k$ is odd greater or equal to $3$. Find this way, direct calculation gives the only example $n=27$.

$(2)$ Case of two prime factors.

If $n=pq$ then $p^2+q^2=2pq+6^2$ so $(p-q)^2=6$ and $n=q(q+6)$ wich is not admissible by the problem. When $p$ or $q$ have an exponent greater than $1$ we apply the reasoning above showing that it is not possible. And nor for three or more prime factors.

Consequently the only solution is $n=27$.


You must log in to answer this question.