跳到正文

题解

AT_abc368_f题解

Celestial_player约 3 分钟
原文
文章信息与版本

文章信息

发布
2024年8月25日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 3 分钟

版本

  1. v1当前

传送门

博弈论水题

题目描述

给定一个长度为 nn 的序列a1,...,ana_1,...,a_n,AnnaAnna和BrunoBruno轮流操作,每次选择 ∀\forall 一个 ii 满足  1≤i≤n\space 1\le i \le n 将 aia_i 变成 xx 满足 x∣aix\mid a_i 且 x≠aix \neq a_i ,由 AnnaAnna 先手,谁先无法操作谁输,求谁会胜利。

题目分析

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

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

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

比如说从 6=2×36=2\times3 到 33 ,从 22 个因子变成 11 个因子

从 48=2×2×2×2×348=2\times2\times2\times2\times3 到 4=2×24=2\times2 ,从 55 个因子变成 22 个因子

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

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

Talk is cheap,show the code:

C++
#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
原文