No.103 Prime Factor Game Returns
タグ : / 解いたユーザー数 301
作問者 :
Problem Statement
Alice and Bob, who learned about prime factors just a little while ago, are playing a number game again.
The rules of the game are as follows.
・You are given $N$ integers, denoted $M_1\ M_2\ \dots M_i \dots \ M_N$.
・The player whose turn it is chooses the $i$-th number among the $N$ integers, divides it by one of the "prime factors of \(M_i \)", and updates the $i$-th number with the quotient.
・In doing so, the player may divide by the same prime factor at least 1 time and at most $2$ times, as long as it is divisible.
For example, if the $i$-th value is \(24\), its prime factors are \(2,3\ (24 = 2 \times 2 \times 2 \times 3) \), so it is possible to update \(24\) to \(6\), the number obtained by dividing it by \(2\) \(2\) times.
・The players take turns repeating the above procedure, and the player who makes all $N$ numbers equal to \(1\) wins.
Alice goes first and starts the game.
Assuming both players play optimally, determine the winner for the given $N$ integers.
Input
$N$ $M_1\ M_2\ \dots M_i \dots \ M_N$
All input values are given as integers.
\( 1 \leq N \leq 100 \)
\( 2 \leq M_i \leq 10,000=10^4 \)
Output
Print the winning player, as the string "Alice" or "Bob", on one line.
Print a newline at the end.
Sample
Sample 1
Input
1 4
Output
Alice
Alice divides \(4\) by its prime factor \(2\) $2$ times and updates it to $1$.
At this point, Alice wins.
Sample 2
Input
2 11 19
Output
Bob
Since both $11$ and $19$ are prime, Bob wins.
Sample 3
Input
1 24
Output
Alice
Alice updates \(24\) by dividing it by \(2^2\), obtaining \(6\).
Bob divides it by \(2\) or \(3\).
The value is now \(2\) or \(3\), and since either one is a prime factor, Alice divides by it and everything becomes 1, so Alice wins.
Sample 4
Input
4 600 1200 1800 2400
Output
Bob
In fact, no matter how Alice divides, Bob has a way to win.
Sample 5
Input
2 6 23
Output
Alice
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。