P2069 Squirrel Eats Fruits
Description
There are $n$ fruits that a squirrel likes to eat, arranged in a vertical column from bottom to top and labeled $1$ to $n$. The squirrel starts from the lowest fruit and jumps upward. On the $i$-th jump, it can skip $(i^3 \bmod 5 + 1)$ fruits at once and then eats the fruit it lands on. After it eats that fruit, if there are fruits above, all of them fall down by one position due to gravity. For example, on the 1st jump it jumps over $(1^3 \bmod 5 + 1 = 2)$ fruits from the first fruit to the third fruit and eats the third; on the 2nd jump it starts from the fourth fruit (which has fallen to the original third position), jumps over $(2^3 \bmod 5 + 1 = 4)$ fruits to the eighth fruit, and eats the eighth; and so on.
Of course, at some point the squirrel will jump beyond the top of this chain; suppose this first happens on the $k$-th jump, so it cannot eat any fruit on that attempt. It then returns to the bottommost fruit and redoes its $k$-th jump, in order to try to eat a fruit. Repeat this process. Given this, what is the label of the $m$-th fruit it eats (i.e., the fruit eaten on the $m$-th successful jump)?
Input Format
Two lines containing $n$ and $m$ respectively ($1 \le m \le n \le 200$), and it is guaranteed that the $m$-th successful jump exists.
Output Format
A single integer: the label of the $m$-th fruit it eats.
Explanation/Hint
Note: The eaten fruits in order are $3$, $8$, $4$ (return to the bottom and redo the 3rd jump), $9$ (return to the bottom and redo the 4th jump).
Translated by ChatGPT 5