At the instant of release
1/2kL^2=1/2(m+M)v_0^2 (Energy)
here v_0 is the initial velocity of m+M
after release
-k(x-x_0) = (m+M) ddot x (Newtonian mechanics)
and solving
x = x_0 + C_1 cos(omegat)+C_2 sin(omegat)
with omega = sqrt(k/(m-M))
The determination of C_1,C_2 is made according to the initial conditions
{(x(0)=x_0-L),(dot x(0) = v_0):}
giving
x = x_0 - L cos(omega t) + v_0/omega sin(omega t)
Now, m,M trip together until ddot x = 0 or when
omega (L omega Cos(omega t) - v_0 Sin(omega t)) = 0 at
t = arctan(v_0/sqrt[L^2 omega^2 + v_0^2], (L omega)/sqrt[
L^2 omega^2 + v_0^2])/omega
The last item is left as an exercise.
NOTE:
Integration of -k(x-x_0) = (m+M) ddot x
First making y = x-x_0 we have
-k/(m+M)y=ddot y now assuming y = e^(lambda t) and substituting
(k/(m+M)+lambda^2)e^(lambda t)=0 so lambda = pm iomega where
omega = sqrt(k/(m+M)) then
y = c_1 e^(i omega t)+c_2 e^(-iomega t)
now using the de Moivre's identity
e^(i omega t) = cos(omegat)+isin(omegat) after some algebric considerations we get equivalently
y = C_1 cos(omegat)+C_2sin(omegat) (note that c_i ne C_i)
and finally
x = x_0 +C_1 cos(omegat)+C_2sin(omegat)