Hide

Problem B
Coconut Splat

/problems/coconut/file/statement/en/img-0001.jpg
Source: WikiMedia

Coconut Splat is one of Theta’s favorite counting-out games. It goes like this: initially, all players stand in a circle with their hands folded together (like an intact coconut). In clockwise order, one player touches the hands of the other players and says the rhyme: “Co-co-nut, Co-co-nut, Co-co-nut, Splat!” At each syllable, the player touches a hand, and the player whose hand or hands is touched last takes one of the following actions:

  • If the player’s hands are still folded, they are split into two fists (the coconut is cracked in two halves). The next round starts with the fist that is the first half of the coconut, then the second half, then going to the next player.

  • If a fist is touched last, the hand is turned palm down (the milk spills out). The next round starts with the next hand in clockwise order, which could be the other hand of the same player, or it could be the hand or folded hands belonging to the next player.

  • If a hand that is already turned palm down is touched last, the player to whom it belongs puts the hand behind their back and this hand won’t be counted in the following rounds. The next round starts with the next hand in clockwise order as in the previous case.

  • If a player has put both of their hands behind their back, that player is out of the game. The game ends when there is only one player left.

The hand or hands of the player doing the counting are taken into account (for instance, the counting player touches their thigh when it would be her turn to be touched).

There are variations of this game, for instance, some kids say “Coconut, coconut, crack your nut!” instead, which has only $9$ instead of $10$ syllables as in the “Co-co-nut, Co-co-nut, Co-co-nut, Splat!” rhyme.

There are $n$ players, and counting always starts with the folded hands of player $1$. For instance, in the first round, if the rhyme has $3$ syllables, player $3$ would be the one to first crack their coconut into two fists.

Write a program that determines the winner of the counting-out game based on the number of players and based on the number of syllables in the rhyme that is used!

Input

The input consists of a single test case with two numbers $s$ ($0 < s \le 100$) and $n$ ($2 \le n \le 100$) denoting the number of syllables in the rhyme and the number of players, respectively.

Output

Output a single integer $p$ ($1 \le p \le n$), the number of the player who is left.

Sample Input 1 Sample Output 1
10 2
2
Sample Input 2 Sample Output 2
10 10
7
Sample Input 3 Sample Output 3
1 2
2

Please log in to submit a solution to this problem

Log in