#P2069. 松鼠吃果子

松鼠吃果子

Description

There are nn fruits that a squirrel likes to eat, arranged in a vertical column from bottom to top and labeled 11 to nn. The squirrel starts from the lowest fruit and jumps upward. On the ii-th jump, it can skip (i3mod5+1)(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 (13mod5+1=2)(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 (23mod5+1=4)(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 kk-th jump, so it cannot eat any fruit on that attempt. It then returns to the bottommost fruit and redoes its kk-th jump, in order to try to eat a fruit. Repeat this process. Given this, what is the label of the mm-th fruit it eats (i.e., the fruit eaten on the mm-th successful jump)?

Input Format

Two lines containing nn and mm respectively (1mn2001 \le m \le n \le 200), and it is guaranteed that the mm-th successful jump exists.

Output Format

A single integer: the label of the mm-th fruit it eats.

10 
4

9

Hint

Note: The eaten fruits in order are 33, 88, 44 (return to the bottom and redo the 3rd jump), 99 (return to the bottom and redo the 4th jump).

Translated by ChatGPT 5