No.153 Pile of Stones
タグ : / 解いたユーザー数 173
作問者 :
nmnmnmnmnmnmnm
Problem Statement
There is 1 pile with $N$ stones stacked in it.
A and B play a game in which they take turns splitting stones.
When splitting, a player divides stones into $2$ piles or $3$ piles.
Let $x$ be a positive integer. Then,
$2x$ stones can be split into $x$ stones and $x$ stones.
$2x+1$ stones can be split into $x$ stones and $x+1$ stones.
$3x$ stones can be split into $x$ stones, $x$ stones, and $x$ stones.
$3x+1$ stones can be split into $x$ stones, $x$ stones, and $x+1$ stones.
$3x+2$ stones can be split into $x$ stones, $x+1$ stones, and $x+1$ stones.
A player may choose any of the above operations.
For example, when there is initially $1$ pile with $5$ stones stacked in it:
Case 1:
Suppose A first splits it into $2$ stones, $2$ stones, and $1$ stone.
B splits a pile of $2$ stones, resulting in $2$ stones, $1$ stone, $1$ stone, and $1$ stone.
A also splits a pile of $2$ stones, resulting in $1$ stone, $1$ stone, $1$ stone, $1$ stone, and $1$ stone.
B cannot split a pile of $1$ stone any further.
Case 2:
Suppose A first splits it into $3$ stones and $2$ stones.
B can split the pile of $3$ stones into $2$ stones and $1$ stone, resulting in $2$ stones, $2$ stones, and $1$ stone.
A splits a pile of $2$ stones, resulting in $2$ stones, $1$ stone, $1$ stone, and $1$ stone.
B also splits a pile of $2$ stones, resulting in $1$ stone, $1$ stone, $1$ stone, $1$ stone, and $1$ stone.
A cannot split a pile of $1$ stone any further.
The player who becomes unable to split stones loses the game.
Therefore, in this game starting with $5$ stones,
A, who moves first, can always win by first splitting the stones into 3 piles, as in Case 1.
When A moves first and both A and B play optimally to win,
determine from the initial N whether A wins or B wins.
Input
N
The number of stones \( N(1 \le N \le 100) \) is given.
Output
Print the name of the winner, \( A \) or \( B \).
Print a newline at the end.
Sample
Sample 1
Input
2
Output
A
A first splits the 2 stones into 1 stone each.
Then B cannot split any further, so A wins.
Sample 2
Input
1
Output
B
A cannot split the stones from the very beginning.
Therefore, B wins.
Sample 3
Input
5
Output
A
This is the same case as in the problem statement.
Sample 4
Input
20
Output
A
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。