#P3198. Planetary Forces on a Line
Planetary Forces on a Line
Planetary Forces on a Line
There are N planets placed on a straight line such that the planet i is located at x = i (1-indexed). Each planet has a mass Mi. For any planet j (where j > 1), it receives a force from a planet i (with i < j) if and only if
\( i \le A \times j \)
where \( A \) is a given small constant. When the force is exerted, the magnitude of the force from planet i to planet j is given by:
\( F_{i\to j} = \frac{M_i \times M_j}{j-i} \)
Your task is to compute the net force acting on each planet. The force on planet 1 is defined as 0 since there are no planets before it. For each planet j (from 2 to N), the net force is the sum of all forces from planets i that fulfill the condition.
Note: An answer is considered correct if the relative error does not exceed 5%.
inputFormat
The first line of input contains two numbers N and A, where N is the number of planets (an integer) and A is a small constant (a floating-point number).
The second line contains N space-separated numbers representing the masses of the planets M1, M2, ..., MN.
outputFormat
Output N lines, where the j-th line contains the net force acting on planet j. For planet 1, output 0. The answers must be accurate within a relative error of 5%.
sample
3 0.5
1 2 3
0.0
2.0
1.5
</p>