There are two objects A, B on a line and a wall is placed at left. A is closer than B to the wall. Initially, A and B are static and each has 1 kg, n kg. Suddenly, B moves toward A with speed 1 m/s and collides. The collision is elastic.
input parameter: a positive integer n (n≤106)
return value: the collision number between A and B or A and wall
Hint: When two objects with mass m_1 and m_2 collide with the initial velocity (not speed) v_1i and v_2i, the final velocity v_1f and v_2f satisfy the equation m_1v_1i+m_2v_2i=m_1v_1f+m_2v_2f. And in elastic collision, the kinetic energy is conserved.