您的位置:首页 > 其它

CodeForces - 346A gcd

2017-07-20 14:48 197 查看

Description

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).

Sample Input

2

2 3

3

5 6 7

Sample Output

Alice

Bob

Hint

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.

题意

A和B玩游戏 给出n个不同的数 A先手 随意找出两个不同的数求他们的差的绝对值

并添加到这个集合中 最终谁无法得到新的数字便输

题解:

可以知道两个不同的数求他们的差的绝对值一定是小于最大的数的 可以求下所有数的最大公倍数 那么他们一共能得到的数的个数为 最大数/最大公倍数-n 然后alice赢得条件为上述个数为奇数

AC代码

#include <cstdio>
typedef long long LL;
int gcd(int a,int b){
return !b?a:gcd(b,a%b);
}
int main(){
int n;
scanf("%d",&n);
int a;
scanf("%d",&a);
int mx = a;
int temp = a;
for (int i = 1; i < n; ++i){
scanf("%d",&a);
if (a>mx) mx = a;
temp = gcd(temp,a);
}
int ans = mx/temp-n;
if (ans%2) printf("Alice\n");
else printf("Bob\n");
return 0;
}


ba61
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: