ACdream群赛1112(Alice and Bob)

题意:http://acdream.info/problem?pid=1112

Problem Description

Here  is Alice and Bob again !

Alice and Bob are playing a game. There are several numbers.First, Alice choose a number n.Then he can replace n (n > 1)with one of its positive factor but not itself or he can replace n with a and b.Here a*b = n and a > 1 and b > 1.For example, Alice can replace 6 with 2 or 3 or (2, 3).But he can’t replace 6 with 6 or (1, 6). But you can replace 6 with 1. After Alice’s turn, it’s Bob’s turn.Alice and Bob take turns to do so.Who can’t do any replace lose the game.

Alice and Bob are both clever enough. Who is the winner?

解法:很好的博弈题。关键是找准每个数的状态。每个数的状态是每个数的分解后的质数的个数。然后就是获得每个数的状态号可以做到On,就是线性筛素数时候顺便将每个数的最小的质数因子筛出来,从小大大先预处理,然后求F(n)就等于F(n/least[n])+1。获得状态号,sg部分就不多说了。


代码:

/******************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//freopen ("in.txt" , "r" , stdin);
using namespace std;

#define eps 1e-8
#define zero(_) (abs(_)<=eps)
const double pi=acos(-1.0);
typedef long long LL;
const int Max=5000010;
const int INF=1000000007;

int f[300];
bool rem[Max];
int out[Max];
int least[Max];
int p=0;
void init()
{
    for(int i=2; i


你可能感兴趣的:(数论,博弈)