This page is still under construction.

Parts of this page are still being built. What you see may change.

twOBoOgEr

Time limit1sMemory limit512 MB

Summary
Count every collision (A-B or A-wall) when B of mass n kg hits resting A of mass 1 kg elastically between a wall and B, for n up to 10^6.
Level

Hard8 of 10

Topics
Math, Simulation, Binary search, Number theory
Solved
No attempts yet

Problem

Write a function P6.

  • There are two objects A and B on a line, with a wall at the left. A is closer to the wall than B. Initially A and B are at rest, with masses 1 kg and nn kg. B suddenly moves toward A at a speed of 1 m/s and collides. The collision is elastic.
  • input parameter: a positive integer nn (n≤106n \le 10^6)
  • return value: the number of collisions between A and B or between A and the wall
  • Hint: When two objects with masses m_1m\_1 and m_2m\_2 collide with initial velocities (not speeds) v_1iv\_{1i} and v_2iv\_{2i}, the final velocities v_1fv\_{1f} and v_2fv\_{2f} satisfy m_1v_1i+m_2v_2i=m_1v_1f+m_2v_2fm\_{1}v\_{1i} + m\_{2}v\_{2i} = m\_{1}v\_{1f} + m\_{2}v\_{2f}. In an elastic collision, kinetic energy is conserved.

Examples1

  1. Example 1

    Input
    1
    
    Expected output
    3