Divide and destroy

3.7

3 votes
Basic Programming, Dynamic Programming, Game Theory, Implementation, Basics of Implementation, Math, Sprague–Grundy Theorem
Problem

Alice and Bob play the game, "Divide and Destroy".

At the beginning of the game, there is a bunch of stones with ni stones. Alice and Bob take turns (Alice is the first). In her turn, Alice can divide any bunch into two. The stones in these new piles are divided equally (if this cannot be done, one more stone is placed in one of them). Bob can destroy any bunch in his turn (pick it up and remove it from the game). If one of the players gets a situation where there is one stone in all the handfuls, he loses.

Which of them will win, with the optimal game of both players.

Input format

  • The first line contains t denoting the number of test cases.
  • The second line contains t numbers ni. Each of these numbers describes a game in which the initial number of stones is ni.

 Output format

You are required to print t lines. Each of these lines contains the answer to the test. If Alice wins, print "Alice" and if Bob wins, print "Bob".

Constraints

t5105

1ni1018

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Since we have a pile of size 2, after Alice's move, there will be two piles of size 1 each, so Bob loses and Alice wins.

Since we have a pile of size 3, Alice will divide this pile into two piles of size 1 and 2, respectively, and Bob will destroy the pile of size 2, Alice will be left with a pile of size 1, she loses, Bob wins.

Editor Image

?