Solution (source code)

= Solution

Under the stated <gauge transformation>, the <charged-particle electromagnetic Lagrangian> becomes
$$
\begin{aligned}
L'&=\frac12m\dot r^2
-q\left(\phi-\partial_tf
 -\dot r\cdot(A+\nabla f)\right)\\
&=L+q\left(\partial_tf+\dot r\cdot\nabla f\right)
 =L+q\frac{df(r(t),t)}{dt}.
\end{aligned}
$$
Thus
$$
\boxed{L'-L=q\,df/dt}.
$$
The action changes only by $q[f(t_2)-f(t_1)]$, whose variation vanishes for fixed endpoints. By <total-time-derivative invariance of a Lagrangian>, the <Euler-Lagrange equation> is unchanged.