Alice and Bob are playing a game.
They start with a positive integer n n n and take alternating turns doing operations on it. Each turn a player can subtract from n one of its divisors that isn’t 1 1 1 or n n n. The player who cannot make a move on his/her turn loses. Alice always moves first.
Note that they subtract a divisor of the current number in each turn.
You are asked to find out who will win the game if both players play optimally.
Input
The first line contains a single integer t ( 1 ≤ t ≤ 1 0 4 ) t (1≤t≤10^4) t(1≤t≤104) — the number of test cases. Then t t t test cases follow.
Each test case contains a single integer n ( 1 ≤ n ≤ 1 0 9 ) n (1≤n≤10^9) n(1≤n≤109) — the initial number.
Output
For each test case output “Alice” if Alice will win the game or “Bob” if Bob will win, if both players play optimally.
Example
input
4
1
4
12
69
output
Bob
Alice
Alice
Bob
Note
In the first test case, the game ends immediately because Alice cannot make a move.
In the second test case, Alice can subtract 2 2 2 making n = 2 n=2 n=2, then Bob cannot make a move so Alice wins.
In the third test case, Alice can subtract 3 3 3 so that n = 9 n=9 n=9. Bob’s only move is to subtract 3 3 3 and make n = 6 n=6 n=6. Now, Alice can subtract 3 3 3 again and n = 3 n=3 n=3. Then Bob cannot make a move, so Alice wins.
结论
- 奇数先手必败 < = = > <==> <==> 非 2 i ( i > 0 ) 2^i(i>0) 2i(i>0)偶数先手必胜。
证明:任意奇数,设
x
x
x,要么是质数,要么可以分解为若干个不包含
2
2
2 的质因数。若是前者,直接输掉;若是后者,那么只能减去一个质数
d
d
d,得到一个偶数
x
−
d
x-d
x−d,由于
x
−
d
x-d
x−d 必然还是
d
d
d 的倍数,所以确切的说,
x
−
d
x-d
x−d 是一个非
2
i
(
i
>
0
)
2^i(i>0)
2i(i>0)的偶数。由于两人足够聪明,再将这个偶数
x
−
d
x-d
x−d 减去
d
d
d ,那么又会变为一个奇数。
综上所述,A若是遇到奇数,他只能把这个数变为偶数,轮到B后,B又将偶数变为奇数,再次轮到A。若干回合后,A最终得到一个奇数质数,从而失败。
- 2 2 2 的奇数次幂必败, 2 2 2 的偶数次幂必胜。
证明:首先 2 1 2^1 21必败。 2 i 2^i 2i ( i i i 为偶数),要么减去 2 i − 1 2^{i-1} 2i−1,变为 2 i − 1 2^{i-1} 2i−1;要么减去其他因数,变为一个非2次幂的偶数(另一个人必胜,这个人必败)。
#include<bits/stdc++.h>
using namespace std;
int n,T;
void solve(){
cin>>n;
if(n&1){ cout<<"Bob\n"; return; }
if(n-(n&-n)){ cout<<"Alice\n"; return; }
int bit=1;
while((1<<bit)<n) bit++;
if(bit&1) cout<<"Bob\n";
else cout<<"Alice\n";
}
int main(){
ios::sync_with_stdio(false);
for(cin>>T;T;T--) solve();
}