TITLE: How many triangular numbers have exactly $d$ divisors?
QUESTION [6 upvotes]: The triangular numbers $T_n$ are defined by $$T_n = \frac{n(n + 1)}{2}.$$ 

Given a positive integer $d$, how many triangular numbers have exactly $d$ divisors, and how often do such numbers occur?

For $d = 4, 8$ the answer seems to be "infinitely many, and often"; for $d = 6$, it seems to be "infinitely many, but rarely"; and for $d \geq 3$ prime the answer is "none" (I think I can prove this). Given $d$ such that there are infinitely many such triangular numbers, can we say anything about the asymptotic gaps between them?
Here is a plot of the number of divisors of $T_n$ as $n$ ranges from $0$ to $50,000$:

The OEIS contains some sequences related to this question, namely A292989 and A068443, but I can't learn enough from the comments there to settle this question for arbitrary $d$.
Edit: The "none" claim for prime $d$ only holds when $d > 2$, as @BarryCipra pointed out.

REPLY [6 votes]: This is a partial answer. Write $\sigma_0(k)$ for the number of divisors of $k$. Note that $n$ and $n+1$ are relatively prime. If $\sigma_0(T_n)$ is odd, then either $n$ is even and both $\frac{n}{2}$ and $n+1$ are squares or $n$ is odd and both $n$ and $\frac{n+1}{2}$ are squares (note that in particular this implies that in the first case $n\equiv 0\mod{8}$ and in the second $n\equiv 1\mod{8}$). Simplifying, one sees that odd values of $\sigma_0(T_n)$ arise from solutions to the Pell equation
$$a^2-2b^2 = \pm 1.$$
So there are an infinite number of $n$ for which $\sigma_0(T_n)$ is odd. However, since $\sigma_0$ is multiplicative, $\sigma_0(T_n)$ cannot be prime unless $n=2$.
Next, note that $\sigma_0(T_n)=4$ means that either $n$ is even and $\sigma_0\left(\frac{n}{2}\right) = \sigma_0(n+1) = 2$, or $n$ is odd and $\sigma_0(n) = \sigma_0\left(\frac{n+1}{2}\right) = 2$. Thus $\sigma_0(T_n)=4$ if and only if either $\frac{n}{2}$ and $n+1$ are both prime or if $n$ and $\frac{n+1}{2}$ are both prime. The first of these is A005097; the second is A006254.
A similar analysis shows that $\sigma_0(T_n)=6$ requires that one of the two factors (i.e., either $\frac{n}{2}$ and $n+1$, or $n$ and $\frac{n+1}{2}$) be prime and the other be the square of a prime, so the values of $n$ below $200$ are $n=7, 9, 17, 18, 25, 97, 121$. These are presumably rarer than the values for $\sigma_0(T_n)=4$.
In response to the OP's comment below, for fixed odd $d$, both factors must be squares in order that $\sigma_0$ be odd for each. If $T_n = 2\prod p_i^{2r_i}$, then you are looking for a way to write $\prod p_i^{2r_i} = \prod p_i^{2s_i}\prod p_i^{2t_i}$ such that $\prod(s_i+1)\prod(t_i+1) = d$. This doesn't seem like a problem with a straightforward solution in general.