传送门
文章目录
- 题意:
- 思路:
题意:
给你一个数nnn,有两个人博弈,每次可以将nnn减去一个nnn的因子,这个因子不能为111或nnn。当不能操作的人输掉游戏。问你先手赢还是后手赢。
思路:
这个题多写几项很容看出来规律,但是并不了解其原理,所以写个博客记录一下。
分以下三种情况讨论:
(1)n(1)n(1)n是奇数,此时nnn的因子都是奇数,设减去的数为ddd,那么得到的数为x=n−dx=n-dx=n−d,xxx一定为偶数,而且不为222的幂次。
(2)n(2)n(2)n是偶数且不是222的幂次,那么nnn一定含有某个因子为奇数,那么我们可以将nnn减去一个奇数,得到的数一定为奇数。
到这里我们可以证一下为什么先手的nnn是偶数且不是222的幂次的时候是必胜的。
由于nnn是偶数且不是222的幂次,那么我们可以将他变成奇数,而奇数变成的数只能是偶数且不是222的幂次,或者当前的奇数为一个质数不能再变化,这个时候后手一定是输了,否则我们一直将其变成奇数,一直到变成一个质数为止,所以先手必胜。
(3)n(3)n(3)n是222的幂次,首先给出结论,当幂次为偶数的时候先手必胜,否则必败,下面给出证明。
首先我们可以将其变成n/2n/2n/2或者变成一个偶数且不是222的幂次。先看变成一个偶数且不是222的幂次的情况,这样相当于放弃胜利了,把必胜态扔给了对手(上面已经证明这样是必胜的)。那么我们肯定是变成n/2n/2n/2,一直到只剩一个222的时候停止,所以幂次为偶数的时候先手必胜。
// 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;
}
/**/