# Find all primes $p$ such that $p^3-4p+9$ is a perfect square.

Find all primes $p$ such that $p^3-4p+9$ is a perfect square.

I tried a few different values for $p$, namely $2,3,5,7,$ and $11$. The prime $p =2,7,11$ all worked but $p =13$ didn't so it makes me wonder. How can I find all primes such that it is a perfect square?

EDIT: it turns out this is problem P25 in post number #63 at http://artofproblemsolving.com/community/c3h1171106p5665470

• If $p^3-4p+9 = n^2$ then $p^3-4p = n^2-9$, i.e. $(p-2)p(p+2) = (n-3)(n+3)$. I'm not sure if this helps, but it might be a good place to start. Dec 17, 2015 at 21:53
• A small beginning: $p^3-4p+9$ is always divisible by three. But it is divisible by nine only when $p\equiv\pm2\pmod9$. This rules out primes not satisfying that congruence. Dec 17, 2015 at 21:54
• Also sprach Mathematica: Those three are the only primes that work among the 10000 smallest primes. Dec 17, 2015 at 22:02
• @Myself , I like to check these things without restricting the variable to be prime. Sometimes that condition is a deliberate red herring to disguise the real techniques for dealing with the problem. Dec 17, 2015 at 22:08
• A related question: it seems that $m^4 + 24m +16$ is a square only when $m=3$ (I checked up to $m = 50000000$). Arrive at that by solving for $p$ in the equation $p^3 - 4p + 9 = (mp + 3)^2$ (there is also the case of $mp-3$ I suppose.
– tkr
Dec 17, 2015 at 22:57

If $p^3-4p+9=n^2$ then $n^2\equiv 9 \pmod{p}$ and $\pm n \equiv 3 \pmod{p}$ since $n^2-9\equiv 0$ can only have two roots modulo a prime.

By choosing the appropriate sign we can write \begin{align} n^2=(-n)^2 &= (kp+3)^2 \\ p^3-4p+9 &= k^2p^2+6kp+9 \\ 0 &= p^2-k^2p-(6k+4) \\ p & = \frac{k^2\pm \sqrt{k^4+24k+16}}{2} \end{align} where we used $p\ne 0$ since it's a prime. This can only have an integer solution for $p$ when $k^4+24k+16$ is a square (as @tkr suggested in the comments). But $$\begin{array}{ll} (k^2-1)^2 = k^4-2k^2+1 < k^4+24k+16<(k^2)^2 & \text{if }k<-11 \\ (k^2)^2 < k^4+24k+16< k^4+2k^2+1 =(k^2+1)^2 & \text{if }k>12 \end{array}$$ so if $k<-11$ or $k>12$ then $k^4+24k+16$ lies between two squares and hence is not a square. This leaves 24 values to check, which you could do by hand. It leads to solutions when $k=-3,0,3$ which give integral values for $p$ of $-2,2,7,11$, of which only $2,7,11$ would normally be considered prime.

• I got to your $p^2-k^2p-(6k+4) = 0$ and solved for $k$ with the quadratic formula, but did not think to solve for $p$ with the quadratic formula, which is what does the job. Dec 18, 2015 at 18:32
• Anyway, well done, and you also posting on AOPS is the right outcome. Dec 18, 2015 at 19:52
• Here is a less involved solution on AoPS. Dec 19, 2020 at 8:04

Zander's solution is nice, but there might be a way to reduce the number of cases to check. when $$k\leq -6$$ or $$k\geq 7$$
$$(k^2-2)^2
but $$k^4+24k+16=k^4,(k^2-1)^2,(k^2+1)^2$$ don't have solutions. (compare parity for $$(k^2-1)^2$$ and $$(k^2+1)^2$$)
so $$-5\leq k\leq 6$$
also observe 3|k. if not, $$k^4+24k+16\equiv 2\pmod3$$ , which is not a square.
now $$k\in\{-3,0,3,6\}$$ , of which 3 out of the 4 cases yield solutions.

question is from turkey NMO 2009, 2nd round, q1: https://artofproblemsolving.com/community/c6h364542