E - Alice and Bob

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
 

It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).

If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.

Input

The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the set.

Output

Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).

Examples
input
2
2 3
output
Alice
input
2
5 3
output
Alice
input
3
5 6 7
output
Bob
Note

Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

 

 

起初一眼以为是一道博弈问题,后来发现就是一个GCD();

 

求出GCD();后即可做倍数。

注意最后要-n

 

附AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int gcd(int a, int b)
 5 {
 6     return (b>0)?gcd(b,a%b):a;  
 7 }
 8 
 9 int main()
10 {
11     int n, a[120], i;
12         cin>>n;
13         int Max = 1;
14         for(i = 0; i < n; i++)
15         {
16             cin>>a[i];
17             if(a[i] > Max)
18                 Max = a[i];
19         }
20         int p = a[0];  
21         for(i = 1; i < n; i++)
22             p = gcd(p, a[i]);
23         int ans = Max/p - n;
24         printf(ans&1 ? "Alice\n" : "Bob\n");
25     return 0;
26 }

 

posted @ 2016-09-26 11:55  Kiven#5197  阅读(196)  评论(0编辑  收藏  举报