( Problem B ) Prime Game
Practice
4.3 (10 votes)
Algorithms
Dynamic programming
Easy
Two dimensional
Problem
53% Success 1006 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Alice and Bob have an integer \(x\) consisting only of digits 2,3,5,7. They are playing a game with this number. 

The rules of the game are as follows:

  • Alice starts the game and then both of them take alternating turns.
  • In each turn, the player removes one digit either from the front or back of the integer \(x\) in the decimal notation. For example, if the player has the integer \(53722\), then he or she might remove \(5\) from the front to obtain \(3722\) or \(2\) from the back to obtain \(5372\).
  • The player who reduces the given integer to a prime number loses the game.

Note that when the number is reduced to one digit, it will always become a prime number, as it will be equal to one of 2,3,5 or 7.

Determine who wins the game if both play optimally.

Input:

  • First line: \(t \) (number of test cases)
  • Next \(t\) lines: Contains the description of \(t \) test cases. Each test case is described in a single line with an integer \(x\).

Note:

  • It is guaranteed that the integer \(x\) consists of only digits \(2, 3, 5,\) and \(7\).
  • The integer \(x\) is not a prime number.

Output:

For each test case:

  • If Alice wins, then print 'Alice' (without quotes) in a single line.
  • If Bob wins, then print 'Bob' (without quotes) in a single line.

Scoring:

In all test sets, \(1 \leq t \leq 10\).

In the first test set worth 35 points,  \(1 \leq x \leq 10^6\).

In the second test set worth 50 points, \(1 \leq x \leq 10^{12}\).

In the third test set worth 15 points, \(1 \leq x \leq 10^{18}\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
33 votes
Tags:
ApprovedBasic ProgrammingEasyOpenTwo dimensional
Points:20
21 votes
Tags:
ApprovedCombinatoricsDynamic ProgrammingEasyMathOpen
Points:20
21 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingEasyOpenTwo dimensional