Example 4 Let $a$ be a real number greater than zero. It is known that there exists a unique real number $k$, such that the quadratic equation in $x$
$$
x^{2}+\left(k^{2}+a k\right) x+1999+k^{2}+a k=0
$$

has two roots that are both prime numbers. Find the value of $a$.
(1999, National Junior High School Mathematics Competition)
Let the two prime roots of the equation be $p, q$. By the relationship between roots and coefficients, we have
$$
\begin{array}{l}
p+q=-k^{2}-a k, \\
p q=1999+k^{2}+a k . \\
\text { Adding (1) and (2) gives } p+q+p q=1999, \text { i.e., } \\
(p+1)(q+1)=2^{4} \times 5^{3} .
\end{array}
$$

From equation (3), it is clear that $p$ and $q$ cannot be 2, so they must be odd.
Thus, $\frac{p+1}{2}$ and $\frac{q+1}{2}$ are both positive integers, and
$$
\frac{p+1}{2} \cdot \frac{q+1}{2}=2^{2} \times 5^{3} \text {. }
$$

If $\frac{p+1}{2}$ is odd, then it must be $\frac{p+1}{2}=5^{r} (r=1, 2, 3)$. Therefore, $p=2 \times 5^{r}-1$ is a composite number, which is a contradiction.
So, $\frac{p+1}{2}$ must be even.
Similarly, $\frac{q+1}{2}$ is also even.
Therefore, $\frac{p+1}{4}$ and $\frac{q+1}{4}$ are both positive integers, and
$$
\frac{p+1}{4} \cdot \frac{q+1}{4}=5^{3} \text {. }
$$

Assume without loss of generality that $p \leqslant q$, then $\frac{p+1}{4}=1$ or 5.
When $\frac{p+1}{4}=1$, $\frac{q+1}{4}=5^{3}$. Solving gives $p=3$, $q=499$, both of which are prime numbers.

When $\frac{p+1}{4}=5$, $\frac{q+1}{4}=5^{2}$. Solving gives $p=19$, $q=99$, but $q$ is a composite number, which does not meet the requirements.
In summary, $p=3, q=499$.
Substituting into equation (1) gives
$$
k^{2}+a k+502=0 \text {. }
$$

According to the problem, equation (1) has a unique real root. Therefore, $\Delta=a^{2}-4 \times 502=0$.
Thus, $a=2 \sqrt{502}$.