How many ordered pairs $(b, g)$ of positive integers with $4 \leq b \leq g \leq 2007$ are there such that when $b$ black balls and $g$ gold balls are randomly arranged in a row, the probability that the balls on each end have the same colour is $\frac{1}{2}$ ?
(A) 60
(B) 62
(C) 58
(D) 61
(E) 59
Consider arranging the $b+g$ balls in a row by first randomly choosing one ball placing it in the leftmost position, then randomly choosing another ball and placing it in the rightmost position, and then the choosing and placing the rest of the balls.

For both end balls to be black, the first ball must be black (the probability of this $\frac{b}{b+g}$ ) and then the second ball must be black (there are $b+g-1$ balls remaining of which $b-1$ is black so the probability is $\left.\frac{b-1}{b+g-1}\right)$, and the remaining balls can be placed in any way. Thus, the probability that both end balls are black is $\frac{b}{b+g} \cdot \frac{b-1}{b+g-1}$.

Similarly, the probability that both end balls are gold is $\frac{g}{b+g} \cdot \frac{g-1}{b+g-1}$. Thus, the probability that both end balls are the same colour is

$$
\frac{b}{b+g} \cdot \frac{b-1}{b+g-1}+\frac{g}{b+g} \cdot \frac{g-1}{b+g-1}
$$

which we know should be equal to $\frac{1}{2}$.

Thus,

$$
\begin{aligned}
\frac{b}{b+g} \cdot \frac{b-1}{b+g-1}+\frac{g}{b+g} \cdot \frac{g-1}{b+g-1} & =\frac{1}{2} \\
b(b-1)+g(g-1) & =\frac{1}{2}(b+g)(b+g-1) \\
2 b^{2}-2 b+2 g^{2}-2 g & =b^{2}+g^{2}+2 b g-b-g \\
b^{2}-2 b g+g^{2} & =b+g \\
(g-b)^{2} & =b+g
\end{aligned}
$$

Set $g-b=k$. (Since $g \geq b$, then $k \geq 0$.)

Therefore, $b+g=k^{2}$.

Adding these two equations, we obtain $2 g=k^{2}+k$, so $g=\frac{1}{2}\left(k^{2}+k\right)=\frac{1}{2} k(k+1)$.

Subtracting these two equations, we obtain $2 b=k^{2}-k$, so $b=\frac{1}{2} k(k-1)$. (This tells us that $g$ and $b$ are consecutive triangular numbers.)

Since $b \geq 4$, then $k(k-1) \geq 8$ so $k \geq 4$.

(If $k=3$, the left side, which increases with $k$, equals 6 ; if $k=4$, the left side equals 12.)

Since $g \leq 2007$, then $k(k+1) \leq 4014$ so $k \leq 62$.

(If $k=63$, the left side, which increases with $k$, equals 4032 ; if $k=62$, the left side equals 3906.)

Therefore, $4 \leq k \leq 62$, so there are $62-4+1=59$ possible values for $k$, and so 59 possible pairs $(b, g)$.