Solution (source code)

= Solution

With $\mathbf d=\mathbf q_1-\mathbf q_2$ and $r=|\mathbf d|$, the <Lagrangian> is
$$
L=\frac12\sum_{j=1}^3m_j|\dot{\mathbf q}_j|^2-f(r).
$$
At configurations with $r>0$, the <Euler-Lagrange equations> give
$$
m_1\ddot{\mathbf q}_1=-\frac{f'(r)}r\mathbf d,\qquad
m_2\ddot{\mathbf q}_2=\frac{f'(r)}r\mathbf d,\qquad
m_3\ddot{\mathbf q}_3=0.
$$
These formulas apply on the differentiable part of the potential; collision configurations require any additional smooth extension of $f(|\mathbf d|)$ to be specified. Summing the equations gives
$$
\frac d{dt}\sum_jm_j\dot{\mathbf q}_j=0,
$$
so the total <linear momentum> is conserved. The total <energy> is
$$
E=\frac12\sum_jm_j|\dot{\mathbf q}_j|^2+f(r).
$$
Differentiating, the two interacting forces do work $-f'(r)\dot r$, while the potential derivative is $f'(r)\dot r$ and particle three contributes no force term. Hence $\dot E=0$. Both \b[total momentum and total <energy> are conserved].