1001 (HDU4861) Couple Doubi
题目描述:
DouBiXp has a girlfriend named DouBiNan.One day they felt veryboring and decided to play some games. The rule of this game is as following.There are k balls on the desk. Every ball has a value and the value of ith(i=1,2,...,k) ball is 1^i+2^i+...+(p-1)^i (mod p). Number p is a prime numberthat is chosen by DouBiXp and his girlfriend. And then they take balls in turnand DouBiNan first. After all the balls are token, they compare the sum ofvalues with the other ,and the person who get larger sum will win the game. Youshould print “YES” if DouBiNan will win the game. Otherwise you should print“NO”.
大意:
Alice 和Bob 玩拿球游戏,座子上有 k 个球 Alice和Bob选定一个素数p,那么第i个球的价值是1^i+2^i+...+(p-1)^i (mod p) ,Alice 和 Bob每次从中取一个球,Alice先取,所有球取完后手中求价值大的那个人获胜(平局无赢家),问Alice是否能获胜。
解答:
首先,这道题是水题,打表很快就能找出来规律。
官方解法:
参考资料(from百度百科):
1.费马小定理
费马小定理是数论中的一个重要定理,其内容为:假如p是质数,且(a,p)=1,那么 a^(p-1) ≡1(mod p)。即:假如a是整数,p是质数,且a,p互质,那么a的(p-1)次方除以p的余数恒等于1。
2.原根
设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根。
3.阶
对于(a,n)=1的整数,满足a^r≡1 (mod n )的最小整数r,称为a模n的阶。