We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Game Theory
  4. Alice and Bob's Silly Game

Alice and Bob's Silly Game

Problem
Submissions
Leaderboard
Discussions
Editorial

Alice and Bob invented the following silly game:

  • The game starts with an integer, , that's used to build a of distinct integers in the inclusive range from to (i.e., ).
  • Alice always plays first, and the two players move in alternating turns.
  • During each move, the current player chooses a prime number, , from . The player then removes and all of its multiples from .
  • The first player to be unable to make a move loses the game.

Alice and Bob play games. Given the value of for each game, print the name of the game's winner on a new line. If Alice wins, print Alice; otherwise, print Bob.

Note: Each player always plays optimally, meaning they will not make a move that causes them to lose the game if some better, winning move exists.

Input Format

The first line contains an integer, , denoting the number of games Alice and Bob play.
Each line of the subsequent lines contains a single integer, , describing a game.

Constraints

Subtasks

  • for of the maximum score

Output Format

For each game, print the name of the winner on a new line. If Alice wins, print Alice; otherwise, print Bob.

Sample Input 0

3
1
2
5

Sample Output 0

Bob
Alice
Alice

Explanation 0

Alice and Bob play the following games:

  1. We are given , so . Because Alice has no valid moves (there are no prime numbers in the set), she loses the game. Thus, we print Bob on a new line.
  2. We are given , so . Alice chooses the prime number and deletes it from the set, which becomes . Because Bob has no valid moves (there are no prime numbers in the set), he loses the game. Thus, we print Alice on a new line.
  3. We are given , so . Alice chooses the prime number and deletes the numbers and from the set, which becomes . Now there are two primes left, and . Bob can remove either prime from the set, and then Alice can remove the remaining prime. Because Bob is left without a final move, Alice will always win. Thus, we print Alice on a new line.

Author

raman_1729

Difficulty

Medium

Max Score

30

Submitted By

6062

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature