Deleting Divisors(博弈论,数学)

CF 1537D

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(1t104) — 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(1n109) — 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.

结论

  1. 奇数先手必败 < = = > <==> <==> 2 i ( i > 0 ) 2^i(i>0) 2ii>0偶数先手必胜。

证明:任意奇数,设 x x x,要么是质数,要么可以分解为若干个不包含 2 2 2 的质因数。若是前者,直接输掉;若是后者,那么只能减去一个质数 d d d,得到一个偶数 x − d x-d xd,由于 x − d x-d xd 必然还是 d d d 的倍数,所以确切的说, x − d x-d xd 是一个非 2 i ( i > 0 ) 2^i(i>0) 2ii>0的偶数。由于两人足够聪明,再将这个偶数 x − d x-d xd 减去 d d d ,那么又会变为一个奇数。
综上所述,A若是遇到奇数,他只能把这个数变为偶数,轮到B后,B又将偶数变为奇数,再次轮到A。若干回合后,A最终得到一个奇数质数,从而失败。

  1. 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} 2i1,变为 2 i − 1 2^{i-1} 2i1;要么减去其他因数,变为一个非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();
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_51864047

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值