规律是最大数减n,奇数则Alice,偶数则Bob
关键:最大数要先除以所有数的公约数
例如:
3
5 6 7
可以如下
Alice:1(7-6) 5 6 7
Bob:1 2(7-5) 5 6 7
Alice:1 2 3(5-2) 5 6 7
Bob:1 2 3 4(6-2) 5 6 7
轮到Alice了,但所有数两两绝对值都包含在内了,所以Alice输
如果
3
10 12 14
最后一组会是
Bob:2 4 6 8 10 12 14
所以需要预先求出所有数的最大公约数
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
LL a[110];
LL gcd (LL a,LL b) {
if (a == 0) { return 0;}
else { return (b == 0) ? a : gcd (b, a % b);}
}
int main() {
int n; LL maxn=0; scanf ("%d",&n);
for (int i=0; i<n; i++) {
scanf ("%I64d",&a[i]);
maxn=max (a[i],maxn);
}
LL ans=maxn;/*the largest one*/
for (int i=0; i<n-1/*!*/; i++) {
for (int j=i+1/*!*/; j<n; j++) {
int t=gcd (a[i],a[j]);
ans=gcd (ans,t);//gcd of all numbers
}
}
printf ( ( ( (maxn/ans)-n) %2==1) ?"Alice\n":"Bob\n");
return 0;
}