4. Let $p \geq 3$ be a prime number, and consider the right triangle with the larger leg $p^{2}-1$ and the smaller leg $2p$. We inscribe a semicircle in the triangle whose diameter lies on the larger leg of the triangle and is tangent to the hypotenuse and the smaller leg of the triangle. Find the values of $p$ for which the radius of the semicircle is an integer.
Solution. In the right triangle $ABC$, we consider $\overline{AB}=p^{2}-1$, $\overline{AC}=2p$.

![](https://cdn.mathpix.com/cropped/2024_04_26_0518c9e7e0d4cca47497g-4.jpg?height=328&width=570&top_left_y=1389&top_left_x=688)

By the Pythagorean Theorem, we have $\overline{BC}^{2}=\overline{AC}^{2}+\overline{AB}^{2}$, so

$\overline{BC}^{2}=(2p)^{2}+\left(p^{2}-1\right)^{2}=4p^{2}+p^{4}-2p^{2}+1=p^{4}+2p^{2}+1=\left(p^{2}+1\right)^{2}$, from which we obtain that $\overline{BC}=p^{2}+1$.

Let $r$ be the radius of the semicircle, $E$ the center of the circle on side $AB$, and $F$ the point of tangency of the semicircle with side $BC$. We have $\overline{AE}=\overline{EF}=r$. On one hand, the area of triangle $ABC$ is given by

$$
\text{Area}(ABC)=\frac{1}{2} \overline{AB} \cdot \overline{AC}=\left(p^{2}-1\right) p
$$

On the other hand,

$$
\begin{gathered}
\text{Area}(ABC)=\text{Area}(AEC)+\text{Area}(ECB)=\frac{1}{2} \overline{AE} \cdot \overline{AC}+\frac{1}{2} \overline{BC} \cdot \overline{EF}= \\
\frac{1}{2} r \cdot 2p+\frac{1}{2}\left(p^{2}+1\right) \cdot r=\frac{r}{2}\left(p^{2}+2p+1\right)=\frac{r}{2}(p+1)^{2}
\end{gathered}
$$

Equating the two expressions for the area of triangle $ABC$, we get

$$
\frac{r}{2}(p+1)^{2}=\left(p^{2}-1\right) p
$$

from which

$$
r=\frac{\left(p^{2}-1\right) 2p}{(p+1)^{2}}=\frac{2p(p-1)}{p+1}
$$

It is a simple calculation to verify that

$$
2p-4<\frac{2p(p-1)}{p+1}<2p
$$

so the only possible values for $r$ are $2p-1$, $2p-2$, and $2p-3$.

- If $r=2p-1$, then

$$
2p-1=\frac{2p(p-1)}{p+1} \Longrightarrow 2p^{2}+2p-p-1=2p^{2}-2p \Longrightarrow p=\frac{1}{3}
$$

- If $r=2p-2=2(p-1)$, then

$$
2(p-1)=\frac{2p(p-1)}{p+1} \Longrightarrow 1=\frac{2p}{p+1} \Longrightarrow p=1
$$

- If $r=2p-3$, then

$$
2p-3=\frac{2p(p-1)}{p+1} \Longrightarrow 2p^{2}+2p-3p-3=2p^{2}-2p \Longrightarrow p=3
$$

Therefore, the only valid solution is $p=3$, which gives the value of $r=3$.