CF346A Alice and Bob(博弈+gcd)

Alice and Bob

求n个数的gcd 最后的数列必然是一个以gcd为首项,公差为gcd的等差数列
比如:2 4 6 显然结束
1 3 5 虽然也是等差数列,但还可以继续下去

所以这题的做法就是求n的数的gcd,然后就可以求出这个数列最长为多少,减掉初始的n

Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a));
#define lowbit(x) (x & -x)
#define lrt nl, mid, rt << 1
#define rrt mid + 1, nr, rt << 1 | 1
template <typename T>
inline void read(T& t) {
    t = 0;
    int f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        t = t * 10 + ch - '0';
        ch = getchar();
    }
    t *= f;
}
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll Inf = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x7f7f7f7f;
const double eps = 1e-5;
const double Pi = acos(-1);
const int maxn = 110;

int an[maxn];

int main(void) {
    int n;
    read(n);
    for (int i = 1; i <= n; i++)
        read(an[i]);
    int k = an[1];
    for (int i = 2; i <= n; i++)
        k = __gcd(k, an[i]);
    sort(an + 1, an + n + 1);
    k = an[n] / k - n;
    if (k & 1)
        printf("Alice\n");
    else
        printf("Bob\n");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值