Instead of memorizing formulas here, you should be working for understanding the process: How fast does X work? How fast does Y work? In a given time $t$, how much can they each accomplish? Now assume that their work is additive (which is why I hate questions stated this way, because when two or more people work on the same project, their work is seldom ever additive - yet these problems depend on your assuming that it is, even though they give you no cause to believe it).
In your example X works at a rate of $\frac14\frac{\text{project}}{\text{hour}}$, Y works at a rate of $\frac16\frac{\text{project}}{\text{hour}}$. In $t$ hours, X does $\frac t4$ of the project, and Y does $\frac t6$ of the project (with that unjustified additive assumption), so together they do
$$ \frac t4 + \frac t6 = t\left(\frac14 + \frac16\right) = \frac5{12}t$$
of the project. If $t$ is the time to complete the project together, then $$\frac5{12}t = 1\text{ project}$$ and so $t = \frac {12}5 = 2.4$ hours.
To expand this to more people: Let $T_i$ be the length of time it takes for person $i$ to finish alone.
- The rate of work for person $i$ is $\frac {1 \text{ project}}{T_i\text{ hours}} = \frac{1}{T_i} \frac{\text{project}}{\text{hour}}$
- Let $t$ be the time it takes them to finish working together.
- Person $i$ contributes $t\times\frac{1}{T_i}$ of the project (that unjustified hidden assumption again).
- The sum of everyone's contributions is the entire project. If there are $n$ people total:
$$\frac{t}{T_1} + \frac{t}{T_2} + \ldots + \frac{t}{T_n} = 1$$
$$t\left(\frac{1}{T_1} + \frac{1}{T_2} + \ldots + \frac{1}{T_n}\right) = 1$$
$$t = \frac{1}{\frac{1}{T_1} + \frac{1}{T_2} + \ldots + \frac{1}{T_n}}$$