forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeforces Deleting Divisors.cpp
40 lines (35 loc) · 1011 Bytes
/
Codeforces Deleting Divisors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Alice and Bob are playing a game.
//They start with a positive integer 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 or 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.
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
if(n%2 == 1)
{
cout<<"Bob"<<endl;
}
else
{
int temp = n, i;
for(i = 0; temp > 1; i++)
{
temp /= 2;
}
if(pow(2,i) != n)
cout<<"Alice"<<endl;
else if(i %2 == 0)
cout<<"Alice"<<endl;
else
cout<<"Bob"<<endl;
}
}
return 0;
}