Solution (source code)

= Solution

For a boost along $+x$ at <speed> $v$, the <energy-momentum four-vector> transforms as
$$
\boxed{E'=\gamma(E-vp_x),\quad p_x'=\gamma(p_x-vE/c^2),\quad p_y'=p_y,\quad p_z'=p_z.}
$$
The total four-vector is the sum over the particles. Write $E=\sum_iE_i$ and $\mathbf P=\sum_i\mathbf p_i$. A centre-of-momentum <rest frame> exists when this total is timelike, with $\mathbf V_{\rm CM}=c^2\mathbf P/E$. Boost along $\mathbf P$ and use $P=EV_{\rm CM}/c^2$:
$$
E_{\rm CM}=\gamma_{\rm CM}(E-V_{\rm CM}P)=E/\gamma_{\rm CM}.
$$
Therefore
$$
\boxed{\gamma_{\rm CM}=\frac{\sum_iE_i}{E_{\rm CM}}=\frac1{\sqrt{1-V_{\rm CM}^2/c^2}}.}
$$
The timelike qualification is needed: exactly parallel <photons> alone have null total <four-momentum> and no such <rest frame>.