Alice and Bob play the following game. A series of numbers is written on the blackboard. Alice and Bob take turns choosing one of the numbers, and replace it with one of its positive factor but not itself. The one who makes the product of all numbers become 1 wins. You can assume Alice and Bob are intelligent enough and Alice take the first turn. The problem comes, who is the winner and which number is Alice's first choice if she wins?

Input

This problem contains multiple test cases. The first line of each case contains only one number N (1<= N <= 100000) representing there are N numbers on the blackboard. The second line contains N integer numbers specifying the N numbers written on the blackboard. All the numbers are positive and less than or equal to 5000000.

Output

Print exactly one line for each test case. The line begins with "Test #c: ", where c indicates the case number. Then print the name of the winner. If Alice wins, a number indicating her first choice is acquired, print its index after her name, separated by a space. If more than one number can be her first choice, make the index minimal.

Sample Input

4
5 7 9 12
4
41503 15991 72 16057 

Sample Output

Test #1: Alice 1
Test #2: Bob
View Code

类型:sg组合游戏(博弈)

思路:由于符合sg组合游戏的特征,故可以求单个sg,然后根据sg组合游戏定理可得整个状态的sg值,题中要求如果alice赢还得输出alice的第一步,由sg定理的证明可知,如果ai可选,则则ai必有以后继状态aa,其sg(aa)=sum^sg(ai),由此可得出第一步。

注意点:如果直接由sg函数的定义来求sg,会mle,即使不会,也会tle的;

此时可直接发现规律,对于a,如果对其进行质因式分解为p1^q1*p2^q2......pm^qm;则其sg函数值为(q1+q2+q3+......qm);

并且可发现对于a的任何后继状态其sg值比小于sg(a);故又可简化找第一步的位置。

这题TLE了几次。。。

要看破他的SG值的规律,然后直接DP,不然会TLE。。。

 

posted on 2013-04-17 22:23  SCAU_Xxm  阅读(179)  评论(0)    收藏  举报