Official algorithmic problem description and constraints.
Rudolf and Bernard decided to play a game with their friends. π people stand in a circle and start throwing a ball to each other. They are numbered from 1
1 to π in the clockwise order.
Let's call a transition a movement of the ball from one player to his neighbor. The transition can be made clockwise or counterclockwise.
Let's call the clockwise (counterclockwise) distance from player π¦
For example, if π=7then the clockwise distance from 2
2 to 5
5 is 3
3, and the counterclockwise distance from 2
2 to 5
5 is 4
4.clockwise or counterclockwise. An illustration of this example is shown below.
The game was interrupted after π throws due to unexpected rain. When the rain stopped, the guys gathered again to continue. However, no one could remember who had the ball. As it turned out, Bernard remembered the distances for each of the throws and the direction for some of the throws (clockwise or counterclockwise).
Rudolf asks you to help him and based on the information from Bernard, calculate the numbers of the players who could have the ball after π throws.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.