Factor Game
Practice
3.7 (3 votes)
Mathematics
Prime factorization
Easy Medium
Game theory
Number theory
Problem
95% Success 8530 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code

This time Alice and Bob have devised a new game of numbers to decide who is the better player among the two. Each time they are given n positive integers and they perform an operation on these integers in each turn. In a particular operation a player can choose any 1 of the numbers and divide it with 1 or more prime numbers either once or more than one times. In a particular turn \(12\) can be reduced to any of the following -

\(1) \frac{12}{2} = 6\)

\(2)\frac {12}{2} = 6, \frac{6}{2} = 3\)

\(3) \frac{12}{3} = 4\)

\(4) \frac{12}{2} = 6, \frac{6}{3} = 2\)

\(5) \frac{12}{2} = 6, \frac{6}{2} = 3, \frac{3}{3} = 1\)

Once a number is reduced to 1 it is discarded.

If in a particular turn a player is not able to make any move than he loses. Assuming both will play optimally well and Alice will start first, you have to tell who will win the game. Input-

First line contains an integer n denoting number of integers. \(2nd\) line contains n integers \(A_i\)

Output-

If Alice wins output should be "ALICE" If Bob wins output should be "BOB"

Constraints-

\(1 \le n \le 100000\)
\(1 \le A_i \le 100000\)

Sample Input (Plaintext Link)
4
1 2 3 4

Sample Output (Plaintext Link)
ALICE

Explanation

On factorizing \(1,2,3\) and 4 we have- 1 cannot be divided further.

\(2 = 2^1\)
\(3 = 3^1\)
\(4 = 2^2\)

In first turn Alice picks 4 and divides it by 2 twice. Which reduces it to 1. It is discarded now.

In second turn Bob picks either 2 or 3 and divides it by number itself. It reduces to 1.

Now Alice has just 1 option left either (2 or 3) .

Now all the numbers are reduced to 1 and BOB has no possible operation to perform. Hence he loses.

Time Limit: 1 sec(s) for each input file. Memory Limit: 256 MB Source Limit: 1024 KB Scoring: Score is assigned in case any testcase passes.

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:30
17 votes
Tags:
Dynamic ProgrammingAlgorithmsEasy-MediumMathematicsOpenApprovedGame Theory
Points:30
1 votes
Tags:
GeometryMathematicsapprovedGame TheoryEasy-Medium