AT_abc368_f题解

· · 题解

传送门

博弈论水题

题目描述

给定一个长度为 n 的序列a_1,...,a_n,Anna和Bruno轮流操作,每次选择 \forall 一个 i 满足 \space 1\le i \le n 将 a_i 变成 x 满足 x\mid a_i 且 x \neq a_i ,由 Anna 先手,谁先无法操作谁输,求谁会胜利。

题目分析

这题其实就是Nim游戏板子题

不会的话出门右转【模板】Nim 游戏

我们转换一下思路,将取因子改成删除素因子

比如说从 6=2\times3 到 3 ,从 2 个因子变成 1 个因子

从 48=2\times2\times2\times2\times3 到 4=2\times2 ,从 5 个因子变成 2 个因子

这样就是简单的Nim游戏板子了

按照质因子个数求个异或和即可

Talk is cheap,show the code:

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a;i <= b;++i)
#define per(i,a,b) for(int i = b;i >= a;--i)
typedef long long ll;
const ll Mod = 1e9+9;
inline ll read(){
    ll x = 0,f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-')f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')x = x * 10 + ch - '0',ch = getchar();
    return x * f;
}
void write(ll x){
    if(x < 0)putchar('-'),x = -x;
    if(x > 9)write(x / 10);
    putchar(x % 10 + '0');
    return;
}
ll n,x,ans;
int main(){
    n = read();
    rep(i,1,n){
        x = read();
        ll cnt = 0;
        rep(i,2,(ll)(sqrt(x))){
            while(x % i == 0){
                ++cnt;//计算质因子个数
                x /= i;
            }
        }
        if(x > 1)++cnt;
        ans ^= cnt;
    }
    printf((ans == 0) ? "Bruno" : "Anna");//先手异或和非零则获胜,Nim游戏的结论
    return 0;
}
//撒花qwq