Homework of Politics

题目:

Homework of Politics

After the Politics class, the teacher gives the student a homework.But Nobita and Takeshi don't like this homework at all.So they decide to play a game, and the person who lost will do the homework of them.This game is like this.At first Nobita chose one or more numbers from [1,n], he can chose all numbers,but each number can be chosed at most once.We think that Nobita choses m numbers, which are a1,a2,...,am.And then they will find m heap of stones, for the ith heap of stone, there are ai stones.And then Nobita and Takeshi will play the game in turn, Nobita plays the first turn.On each turn, the person should chose one heap of stones, and take one or more stones from this heap.And if the number of stones in this heap before is N, the number of stones in this heap after is M, N%M=0 and M!=0 are needed (% means the mod operation). The person who can't do anything will lost the game.Now Nobita wants to know how many ways Nobita can chose from [1,n], that will make sure Nobita wins the game.
Input
The first line contains an integer n.
(1<=n<=10^6).
Output
Output the answer % 1000000007.

Sample Input

8
Sample Output

192

 

思路:

首先考虑如何将题目中涉及的博弈问题转化,根据题意,对于一堆石子,其个数为x,我们只能拿(x)的若干个因子,使得剩下的数也是(x)的约数,假设x有$latex f(x) $个素因子,那么就相当于每次只能把(x)的素因子去掉若干个,也就是相当于一个石子数为(f(x))的Nim游戏了。

所以问题就变成了问([1,n])有多少种取法使得对应的f的异或值不为0,注意到一个数的素因子个数是 (O(logn))级别的,对于本题(f(x) < 32),所以就可以dp做了。

设  (f_{i,j} =前i个数,异或值为j的方案数),则$$ f_{i,j} = (f_{i-1,j} + f_{i-1,j\,\land\,f[i]}) \,mod \,1e9+7 $$

 

代码如下:

 

You May Also Like

About the Author: zhuyeye

发表评论

电子邮件地址不会被公开。 必填项已用*标注