TITLE: Find the values of $p$ and $q$
QUESTION [6 upvotes]: If $p^3+p=q^2+q$ where $p$ and $q$ are prime numbers, 
  Find all the solutions (p, q) 

I tried to solve this exercise using that:
$p^2 = -1(\text{mod} \, q)$ and $q = -1(\text{mod} \, p)$; 
   So: $q+1=ap$ and $p^2+1=bq$, where $b$ and $q$ integers. 
Then I tried to solve a quadratic equation, but I could not finish the problem

REPLY [5 votes]: $$p^3+p=q^2+q \implies p|q^2+q \implies p|q\ \mathrm{or}\ p|(q+1).$$
Obviously, $p\neq q$, so $p\nmid q$. Thus, we can set $q=kp-1$. This then reduces to
$$p^2-k^2p+(k+1)=0,$$
which has an integer solution iff $k^4-4k-4$ is a square. Can you see why this is not the case for large $k$, and determine the solutions from there?

REPLY [2 votes]: Remember that if $a,b$ are positive integers such that $a\mid b$ then $a\leq b$. I'll be using this frekvently here.
From $$p(p^2+1)= q(q+1)\implies p\mid q\;\;\;{\rm or}\;\;\;p\mid q+1$$
1. case $p\mid q$, then $q+1\mid p^2+1$. Write $q+1=s$ then we get $$ps\mid (p^2+1)(s-1) = p^2s-p^2+s-1\implies ps\mid p^2-s+1$$
Since $p^2+1\geq s$ we have 2 subcases:
1.1 case $p^2+1>s$, then $ps\leq p^2-s+1$ so $s(p+1)\leq p^2+1$, and thus $$s\leq {p^2+1\over p+1} <p\implies s\leq p-1$$ 
So $q+1\leq p-1 \leq q-1$ and thus no solution.
1.2 case $p^2+1=s$, then $q^2+1 = q+1$ and again no solution.
2. case $p\mid q+1$, then $q\mid p^2+1$. Then we get $$pq\mid (p^2+1)(q+1) = p^2q+p^2+q+1\implies pq\mid p^2+q+1$$
so we have $pq\leq p^2+q+1$ so $q \leq {p^2+1\over p-1} \leq p+2$ if $p\geq 3$. 
So if $p\geq 3$ and since $p\mid q$ that $q\in \{p,p+1,p+2\}$ which is easy to finish by hand.