Task 3. Find all pairs of prime numbers $(p, q)$ for which

$$
p\left(p^{2}-p-1\right)=q(2 q+3)
$$
Solution. Answer: the only solution is $(p, q)=(13,31)$.

If $p=q$, then it must also hold that $p^{2}-p-1=2 q+3=2 p+3$. This can be factored as $(p-4)(p+1)=0$. Since 4 and -1 are not prime numbers, this does not yield any solutions.

In the other case, we have $p \mid 2 q+3$ and $q \mid p^{2}-p-1$. Since $2 q+3$ and $p^{2}-p-1$ are positive, it follows that $p \leq 2 q+3$ and $q \leq p^{2}-p-1$. To find a sharper lower bound for $p$, we multiply the two relations

$$
\begin{aligned}
p q & \leq (2 q+3)\left(p^{2}-p-1\right) \\
& = 2 q p^{2}-2 q p-2 q+3\left(p^{2}-p-1\right) \\
& = 3\left(p^{2}-p-1\right)-2 q
\end{aligned}
$$

where we have discarded terms with a factor $p q$. Note now that $3\left(p^{2}-p-1\right)-2 q \geq$ $3 q-2 q=q>0$. This means that the above divisibility relation leads to

$$
\begin{aligned}
p q & \leq 3\left(p^{2}-p-1\right)-2 q \\
& =3 p^{2}-3 p-(2 q+3) \\
& \leq 3 p^{2}-3 p-p \\
& =3 p^{2}-4 p .
\end{aligned}
$$

If we move $4 p$ to the other side and divide by $p$, we find that $q+4 \leq 3 p$, or

$$
\frac{2 q+3}{6}<\frac{q+4}{3} \leq p
$$

Since $p$ is a divisor of $2 q+3$, we conclude that $2 q+3=k p$ with $k \in\{1,2,3,4,5\}$. If $k=1$, then we have $2 q+3=p$ and thus also $q=p^{2}-p-1$. But then it would hold that $p=2 q+3=2\left(p^{2}-p-1\right)+3=2 p^{2}-2 p+1$. This can be factored as $(2 p-1)(p-1)=0$, which has no solutions with $p$ prime. If $k=2$ or $k=4$, then $k p$ is even. But $2 q+3$ is odd, so these cases are ruled out. If $k=3$, then from $2 q+3=3 p$ it follows that $q$ must be a multiple of 3. Since $q$ is prime, we then have $q=3$, and thus also $p=(2 q+3) / 3=3$. Checking shows that this is not a solution to the original equation.

The last case is $k=5$. Then we have $5 p=2 q+3$ and from the original equation, we have $5 q=p^{2}-p-1$. If we substitute this, we find $25 p=5(2 q+3)=$ $2\left(p^{2}-p-1\right)+15=2 p^{2}-2 p+13$. This can be factored as $(p-13)(2 p-1)=0$. This gives the possible solution $p=13$ with $q=(5 p-3) / 2=31$. We check that $(p, q)=(13,31)$ is indeed a solution to the problem.