wip
Time Limit: 2 seconds
Memory Limit: 256 MB
Rating: 1200
Problem StatementEveryone knows 2D Pong, but what if Pong became 1D? You are given an integer n which represents the size (length) of the board. The pong ball starts on the left and begins travelling to the right. The ball moves one position every unit time. When the ball hits a boundary, the ball reflects and begins travelling in the opposite direction. If it hits the right boundary it will change from travelling right to travelling left and vice versa. Here is an example to give you a better understanding: If n is 5: The board is # # # # # The character “o” represents the ball in this case. At t = 0: o # # # # At t = 1: # o # # # At t = 2: # # o # # At t = 3: # # # o # At t = 4: # # # # o At t = 5: # # # o # At t = 6: # # o # # At t = 7: # o # # # At t = 8: o # # # # At t = 9: # o # # # . . . Since this process continues infinitely, you want to know the position of the ball at time $t$, the time when the game stops and the ball stops moving. *Note: give your answer with 1-indexing. This means that the leftmost position is referred to as position 1, NOT position 0.
InputYou are given an integer $n$, the length of the board and an integer $t$, the time when the game stops, on the first and second lines respectively. $1 \le n \le 6 \cdot 10^6$ $0 \le t \le 10^{18}$
OutputOutput the position that the ball ends at.
Sample CasesSample Input 1: 4 10 Sample Output 1: 3 Sample Input 2: 7 17 Sample Output 2: 6Explanation
Explanation (case 1): At t = 0: o... At t = 1: .o.. At t = 2: ..o. At t = 3: ...o At t = 4: ..o. At t = 5: .o.. At t = 6: o... At t = 7: .o.. At t = 8: ..o. At t = 9: ...o At t = 10: ..o. Explanation (case 2): At t = 0: o...... At t = 1: .o..... At t = 2: ..o.... At t = 3: ...o... At t = 4: ....o.. At t = 5: .....o. At t = 6: ......o At t = 7: .....o. At t = 8: ....o.. At t = 9: ...o... At t = 10: ..o.... At t = 11: .o..... At t = 12: o...... At t = 13: .o..... At t = 14: ..o.... At t = 15: ...o... At t = 16: ....o.. At t = 17: .....o.
SourcesKL Coding Cup March 2023 > Pong > Problem 3
Submit | Back