博弈论水题
题目描述
给定一个长度为 的序列,和轮流操作,每次选择 一个 满足 将 变成 满足 且 ,由 先手,谁先无法操作谁输,求谁会胜利。
题目分析
这题其实就是Nim游戏板子题
不会的话出门右转【模板】Nim 游戏
我们转换一下思路,将取因子改成删除素因子
比如说从 到 ,从 个因子变成 个因子
从 到 ,从 个因子变成 个因子
这样就是简单的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