Ball in a hexagon
In a Cartesian coordinate system (OXY), a regular hexagon is drawn with all sides measuring (1) unit and each angle measuring (120) degrees. The center of the hexagon is at the origin, ((0, 0)), and two of its vertices are located at ((1, 0)) and ((-1, 0)).
At the origin, a small ball, considered as a point mass, is placed. The ball is struck with a cue, causing it to move at a constant speed of one unit per second. This speed corresponds to the length of the segment connecting ((0, 0)) and ((1, 0)). The ball travels in a direction forming a (45)-degree angle with the positive OX axis, as illustrated below:
When the ball hits a side of the hexagon, it reflects off the side according to the law of reflection, where the angle of incidence equals the angle of reflection. The collision is perfectly elastic, so the ball continues moving at the same speed post-impact.
If the ball strikes a corner of the hexagon, it reflects according to the same physical laws. Here, the angle of incidence is measured from one side forming the corner, and the angle of reflection is measured from the other side.
Assume that exactly (T) seconds after the ball starts moving, it reaches the point ((x0, y0)). Write a program that takes the number (T) as input and calculates the value of the sum (x0*x0 + y0*y0).
Input
The input number (T) ranges from (1) to (1,000,000,000) (1 billion) inclusive.
Output
Output a line containing the decimal representation of the real number (S), which is the value of the sum (x0*x0 + y0*y0). The number (S) should be rounded to exactly (3) decimal places according to standard mathematical rounding rules.
To ensure accurate rounding, all test cases will satisfy the condition that (1000*S) is at least (0.1) away from the nearest half-integer (i.e., a number of the form (x + 0.5) for integer (x)).