There are N people in a circle. And a ball is passing clockwise starting from the a-th person (index is 1-based). Asking for the index of the person with the ball after M passes.
If the index is 0-based, the answer could be easily get using the mod operations. Therefore, we first transform the number to 0-based, i.e. a-th person is (a-1) in 0-based.
Then, the answer in 0-based should be (a-1+M)%N.
Finally, the answer in 1-based is (a-1+M)%N+1.
AUTHOR’S AND TESTER’S SOLUTIONS:
Solutions will be available soon.
Author’s solution can be found here.
Tester’s solution can be found here.