# How to obtain the $2s-1$ integrals of motion for a mass with a spring?

In according with Landau's Mechanics the number of independent integrals of motion for a closed mechanical system with $$s$$ degrees of freedom is $$2s-1$$. We can express the $$2s-1$$ arbitrary constants $$C_1,C_2,...,C_{2s-1}$$ as functions of $$q$$ and $$\dot{q}$$, and these functions will be integrals of the motion.

Thus for a mass with a spring we have only 1 integral (the energy), but I do not understand how to obtained it, indeed for $$m\ddot{x}+kx=0$$ I can write: $$x=A\cos{\omega t}+B\sin{\omega t}$$ and $$\dot{x}=-A\omega \sin{\omega t}+B\omega\cos{\omega t}$$. How can I express $$A=f_1(q,\dot{q})$$ and $$B=f_2(q,\dot{q})$$ if, for istance, $$A=x_0$$ and $$B=0$$?

There is a similar question in What is the standard procedure to form the first integrals of a motion? but I don't understand the answer.

$$\ddot x+\omega_0^2\,x=0$$
with $$~x(0)=A~,\dot x(0)=B~$$ you obtain the solution
$$x={\frac {B\sin \left( \omega_{{0}}t \right) }{\omega_{{0}}}}+A\cos \left( \omega_{{0}}t \right) \quad \Rightarrow\\ v=\dot x=B\cos \left( \omega_{{0}}t \right) -A\sin \left( \omega_{{0}}t \right) \omega_{{0}}$$
solve those two equations for $$~A~,B~$$
$$A=-{\frac {v\sin \left( \omega_{{0}}t \right) -x\omega_{{0}}\cos \left( \omega_{{0}}t \right) }{\omega_{{0}}}} \\ B=\sin \left( \omega_{{0}}t \right) x\omega_{{0}}+v\cos \left( \omega_{{0 }}t \right)$$ thus $$~A=f_A\,(q,\dot q)~$$ and $$~B=f_B\,(q,\dot q)~$$ where $$~x=q~$$ and $$~v=\dot q$$