Acdream 1112 Alice and Bob (vegetarian sieve + game sg function)

Source: Internet
Author: User

Alice and BobTime limit:3000MS Memory Limit:128000KB 64bit IO Format:%lld &%llu SubmitStatusPracticeAcdream 1112

Description

Here's Alice and Bob again!

Alice and Bob are playing a game. There is several numbers.

First, Alice choose a number n.

Then he can replace N (n > 1) with one of its positive factor but not itself or he can replace N with A and B. Here a*b = N and a > 1 and b > 1.

For example, Alice can replace 6 with 2 or 3 or (2, 3).

But he can ' t replace 6 with 6 or (1, 6). But the can replace 6 with 1.

After Alice's turn, it ' s Bob's turn. Alice and Bob take turns. Who can ' t does any replace lose the game.

Alice and Bob are both clever enough. Who is the winner?

Input

This problem contains multiple test cases. The first line contains one number N (1≤n≤100000).

The second line contains n numbers.

All the numbers is positive and less than of equal to 5000000.

Output

For each test case, if Alice can win, output "Alice", otherwise output "Bob".

Sample Input

22 232 2 4

Sample Output

Bobalice

Test instructions: Given n heap of stones, each time the number of stones can be divided into two piles or the number of stones in the heap is reduced by the rule,

Whoever can not continue the operation will lose.

The following rules: If N=a*b and a>1,b>1, the stone can be divided into a B two heap, or can be reduced to a or B.

such as n=6, can be divided into (2,3), 2,3 these three kinds of situations, but can not be divided into (1,6), 1,6 these three cases.

And HDU3032 is a problem, is a problem of stone, here is the 8=2*2*2 is that problem in the 3, here

6=2*3 is the 2 in that problem. If you're having trouble understanding this problem, read my previous blog:

Http://www.cnblogs.com/Ritchie/p/5627242.html

That is to say, the problem is the number of elements of each count of the number of operations, that is, the prime can be seen as a 1.

Set a number x=a1^r1*a2^r2*...*an^rn; set sum = R1+r2+...+rn.

Then all the cases can be expressed as:

(1,sum-1), (2,sum-2),... (SUM/2,SUM-SUM/2) or (1), (2),... (n-1)

Then we can calculate the sum in this way.

Set a number to X, and his smallest element factor is Y. Then sum[x] = sum[x/y] + 1;

So we need to record the minimum factor of each number for the above formula when we make a sieve.

#include <iostream>#include<cstring>#include<cstdio>using namespacestd;#defineMAXN 5000050intPrime[maxn],cnt=0;BOOLISPRIME[MAXN];intM[MAXN];intA[MAXN];intsg[ the];voidGetprime () {memset (IsPrime,0,sizeof(IsPrime)); memset (M,0,sizeof(m)); Memset (A,0,sizeof(a));  for(intI=2; i<=maxn; i++)    {        if(!Isprime[i]) {prime[cnt++]=i;  for(intJ=i+i; j<=maxn; j+=i) {isprime[j]=1; if(!m[j]) m[j]=i; } M[i]=i; }    }     for(intI=2; i<=maxn; i++) A[i]=a[i/m[i]]+1;}voidGETSG () {memset (SG,0,sizeof(SG)); sg[0]=0; sg[1]=1; BOOLvis[ the];//in the loop, as defined, it needs to be initialized every time.     for(intI=2; i<= -; i++) {memset (Vis,0,sizeof(VIS));//Notice to initialize each time         for(intj=0; j<i; J + +)//Take Stonesvis[sg[j]]=1;  for(intj=1; j<i; J + +)//Splitvis[sg[j]^sg[i-j]]=1;  for(intx=0;; X + +)            if(!Vis[x]) {Sg[i]=x;  Break; }    }}void Get() {GETSG (); Getprime ();}voidsolve () {intN;  while(SCANF ("%d", &n)! =EOF) {        intdata,ans=0;  for(intI=0; i<n; i++) {scanf ("%d",&data); Ans^=Sg[a[data]]; }        if(ANS) printf ("alice\n"); Elseprintf ("bob\n"); }}intMain () {Get(); Solve ();}

Acdream 1112 Alice and Bob (vegetarian sieve + game sg function)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.