Codeforces Round #726 (Div. 2) D. Deleting Divisors 博弈

传送门

文章目录

题意:

给你一个数 n n n,有两个人博弈,每次可以将 n n n减去一个 n n n的因子,这个因子不能为 1 1 1 n n n。当不能操作的人输掉游戏。问你先手赢还是后手赢。

思路:

这个题多写几项很容看出来规律,但是并不了解其原理,所以写个博客记录一下。
分以下三种情况讨论:
( 1 ) n (1)n (1)n是奇数,此时 n n n的因子都是奇数,设减去的数为 d d d,那么得到的数为 x = n − d x=n-d x=nd x x x一定为偶数,而且不为 2 2 2的幂次。
( 2 ) n (2)n (2)n是偶数且不是 2 2 2的幂次,那么 n n n一定含有某个因子为奇数,那么我们可以将 n n n减去一个奇数,得到的数一定为奇数。
到这里我们可以证一下为什么先手的 n n n是偶数且不是 2 2 2的幂次的时候是必胜的。
由于 n n n是偶数且不是 2 2 2的幂次,那么我们可以将他变成奇数,而奇数变成的数只能是偶数且不是 2 2 2的幂次,或者当前的奇数为一个质数不能再变化,这个时候后手一定是输了,否则我们一直将其变成奇数,一直到变成一个质数为止,所以先手必胜。
( 3 ) n (3)n (3)n 2 2 2的幂次,首先给出结论,当幂次为偶数的时候先手必胜,否则必败,下面给出证明。
首先我们可以将其变成 n / 2 n/2 n/2或者变成一个偶数且不是 2 2 2的幂次。先看变成一个偶数且不是 2 2 2的幂次的情况,这样相当于放弃胜利了,把必胜态扔给了对手(上面已经证明这样是必胜的)。那么我们肯定是变成 n / 2 n/2 n/2,一直到只剩一个 2 2 2的时候停止,所以幂次为偶数的时候先手必胜。

// Problem: D. Deleting Divisors
// Contest: Codeforces - Codeforces Round #726 (Div. 2)
// URL: https://codeforces.com/contest/1537/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;

//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

int n;

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);
	
	int _; scanf("%d",&_);
	while(_--) {
		scanf("%d",&n);
		if(n%2!=0) puts("Bob");
		else {
			int cnt=0;
			while(n%2==0) cnt++,n/=2;
			if(n!=1) puts("Alice");
			else {
				if(cnt%2==0) puts("Alice");
				else puts("Bob");
			}
		}
	}



	return 0;
}
/*

*/









  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值