Hide

Problem F
The Board Game

Ann-Charlotte and Berit have invented their own board game. The game is played with a board of size $N \times M$ and a chainsaw, and is intended for two players. They players take turns making a move until one of them cannot make a move, and that player loses. A move works the following way:

The player whose turn it is chooses a horizontal or vertical line, and splits the board along it into two non-empty parts. This can only be done at integer coordinates (so that the two resulting board pieces have integer dimensions). The other player then chooses which of the pieces the game should continue on, while the other board piece is thrown away. Since the dimensions always have to be integers, the loser will always be the one whose turn it is to use the chainsaw when the board has size $1 \times 1$.

Given the size of the original board, and the fact that Ann-Charlotte always starts, can you determine who wins if both players play optimally?

\includegraphics[width=0.6\textwidth ]{bradspelet.png}
Figure 1: An illustration of the first example

Input

Input consists of one line containing the two numbers $N$ and $M$ ($1 \le N,M \le 100$).

Output

One line with the letter “A” if Ann-Charlotte wins and “B” if Berit wins, given that they both play optimally. More precisely, if Ann-Charlotte can win no matter how Berit plays you should write “A”, otherwise you should write “B”.

Scoring

Your solution will be tested on several groups of test cases. To get points for a group you need to pass all the tests of that group.

Group

Points

Constraints

$1$

$20$

$N, M \le 10$

$2$

$80$

No additional constraints

Explanation of sample 1

In the first example $A$ wins by splitting the board into two pieces of size $1 \times 3$. No matter what $B$ does afterwards, $A$ will get to choose between pieces of size $1 \times 2$ and $1 \times 1$. The correct strategy is to pick $1 \times 2$ (the other option immediately leads to defeat). $B$ will then be forced to choose between two pieces of size $1 \times 1$, which both will result in defeat for $B$.

Sample Input 1 Sample Output 1
2 3
A
Sample Input 2 Sample Output 2
2 6
B
Sample Input 3 Sample Output 3
6 8
A

Please log in to submit a solution to this problem

Log in