HDU-4861 Couple doubi

http://acm.hdu.edu.cn/showproblem.php?pid=4861

Couple doubi

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 675    Accepted Submission(s): 484

Problem Description

DouBiXp has a girlfriend named DouBiNan.One day they felt very boring 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 number that is chosen by DouBiXp and his girlfriend. And then they take balls in turn and DouBiNan first. After all the balls are token, they compare the sum of values with the other ,and the person who get larger sum will win the game. You should print “YES” if DouBiNan will win the game. Otherwise you should print “NO”.

Input

Multiply Test Cases.
In the first line there are two Integers k and p(1<k,p<2^31).

Output

For each line, output an integer, as described above.

Sample Input

2 3

20 3

Sample Output

YES

NO

分析:找规律题,以p-1为一个周期,在p-1的这个位置是数字,其余为0,所以是奇数,就输出yes,否则就no。

这种题一定耐心的把所有情况写出来,看之间的规律。

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int k,p;
    while(~scanf("%d%d",&k,&p))
    {
        if(k/(p-1)%2==0)
          printf("NO\n");
        else
          printf("YES\n");
    }

}

HDU-4861 Couple doubi

时间: 2024-10-25 10:03:09

HDU-4861 Couple doubi的相关文章

HDU 4861 Couple doubi(数论)

HDU 4861 Couple doubi 题目链接 题意:给定k,p,有k个球,每个球的值为1^i+2^i+...+(p-1)^i (mod p) (1 <= i <= k),现在两人轮流取球,最后球的值总和大的人赢,问先手是否能赢 思路:先手不可能输,非赢即平,那么只要考虑每种球的值, 利用费马小定理或欧拉定理,很容易得到该函数的循环节为p - 1, 那么i如果为p - 1的倍数,即为循环节的位置,那么每个值都为1,总和为p - 1 如果i不在循环节的位置,任取一个原根g,根据原根的性质,

2014多校第一场A题 || HDU 4861 Couple doubi

题目链接 题意 : 有K个球,给你一个数P,可以求出K个值,(i=1,2,...,k) : 1^i+2^i+...+(p-1)^i (mod p).然后女朋友先取,再xp取,都希望赢,如果女朋友能赢输出YES,否则输出NO 思路 :这个题,在纸上算算差不多就出来结果了,因为要赢,所以一开始必定拿大的,根据规律可以发现最后的那个取余结果不是0就是某个数,所以就看那个数有奇数个还是偶数个即可. 官方题解: 1 #include <stdio.h> 2 #include <string.h&g

hdu 4861 Couple doubi (找规律 )

题目链接 可以瞎搞一下,找找规律 题意:两个人进行游戏,桌上有k个球,第i个球的值为1i+2i+?+(p−1)i%p,两个人轮流取,如果DouBiNan的值大的话就输出YES,否则输出NO. 分析:解题报告 1 #include <cstdio> 2 #include <iostream> 3 4 using namespace std; 5 int main() 6 { 7 int k, p; 8 while(cin>>k>>p) 9 { 10 if(k/

杭电hdu 4861 Couple doubi

杭电 2014多校联训第一场   1001   Couple doubi   逗比夫妇 这标题我就不多说什么了. 题意:有K个球在桌上,每个球都有价值,第i个球的价值是1^i+2^i+...+(p-1)^i (mod p).其中p是一个素数,之后逗比男先选球,最后所有球总分高的获胜.如果逗比男获胜,那么输出“YES”否则输出“NO”.(逗比男和逗比女都采取最有策略). 当然这也p是奇素数的一个重要公式.曾有题是这个公式求和.当然如果你知道就很简单了.如果不知道,就打表找规律吧. 根据这一重要的公

HDU 4861 Couple doubi(找规律|费马定理)

Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4861 Description DouBiXp has a girlfriend named DouBiNan.One day they felt very boring and decided to play some games. The rule of th

HDU 4861(多校)1001 Couple doubi

Problem Description DouBiXp has a girlfriend named DouBiNan.One day they felt very boring 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)

HDU 4857 Couple doubi(找循环节)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4861 解题报告:桌子上有k个球 ,第i个球的价值wi = 1^i+2^i+...+(p-1)^i (mod p),现在两个人轮流取,如果第一个取的人最后得到的价值总和最大,输出YES,否则 输出NO . k和p的范围都很大,如果都算出来那是不可能的,所以一定是有规律的,所以我把前面的几个打表看了一下,果然有规律,第1.2.3.......(p-2),(p-1)个球的价值分别是: 0,0,0.....

HDU 4861

http://acm.hdu.edu.cn/showproblem.php?pid=4861 结论题:p是奇素数,1^n+2^n+...+(p-1)^n=0(mod p),其中p-1不整除n #include <iostream> #include <cstdio> #include <cstring> #include <set> #include <cmath> #include <map> #include <queue&

HDU-4861-Couple doubi(数学题,难懂!难懂!)

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4861 这个题只能说没弄懂,感觉很难,看博客也看不懂,只能,多看几次,看能不能有所突破了. 代码的话只有几行, #include<stdio.h>int main(){ int k,p; while(scanf("%d%d",&k,&p)!=EOF) { k=k/(p-1); if(k&1) printf("YES\n"); else