Skip to content

Commit 1f4cf25

Browse files
Create Codeforces Deleting Divisors.cpp
1 parent 4061208 commit 1f4cf25

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//Alice and Bob are playing a game.
2+
3+
//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.
4+
5+
//Note that they subtract a divisor of the current number in each turn.
6+
7+
//You are asked to find out who will win the game if both players play optimally.
8+
9+
#include<iostream>
10+
using namespace std;
11+
12+
int main()
13+
{
14+
int t;
15+
cin>>t;
16+
while(t--)
17+
{
18+
int n;
19+
cin>>n;
20+
if(n%2 == 1)
21+
{
22+
cout<<"Bob"<<endl;
23+
}
24+
else
25+
{
26+
int temp = n, i;
27+
for(i = 0; temp > 1; i++)
28+
{
29+
temp /= 2;
30+
}
31+
if(pow(2,i) != n)
32+
cout<<"Alice"<<endl;
33+
else if(i %2 == 0)
34+
cout<<"Alice"<<endl;
35+
else
36+
cout<<"Bob"<<endl;
37+
}
38+
}
39+
return 0;
40+
}

0 commit comments

Comments
 (0)