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 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

//打表找规律的代码
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(void)
{
    int i,j,k,p;
    int value[100];
    while(scanf("%d%d",&k,&p)!=EOF)
    {
        memset(value,0,sizeof(value));
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<p;j++){
                value[i]=(int)(value[i]+pow(j,i))%p;
            }
            printf("%d ",value[i]);
        }
        printf("\n");
    }
    return 0;
}
/*
打表找了下规律,发现2的时候所有球都是1,
3的时候是0 2 0 2 0 2 0 2···交替,
5的时候是0 0 0 4 0 0 0 4 0 0 0 4···,
7 的时候是0 0 0 0 0 6 0 0 0 0 0 6·····,这样规律就出来了。
*/
//ac
#include<stdio.h>
int main()
{
    int k, p;
    while(~scanf("%d%d", &k, &p))
    {
        if((k/(p-1))%2==1)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
//费马定理神马看这里吧!
http://blog.csdn.net/u011439796/article/details/38048963

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

时间: 2024-08-05 07:05:36

HDU 4861 Couple doubi(找规律|费马定理)的相关文章

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(数论)

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 4952 Number Transformation (找规律)

题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值,求出这个固定的值和K相乘就可以了, 为什么会趋于固定的值呢,因为最后虽然i在不断增长,但是x也是在增长的,每次的倍数会回退一个发现 有余数,然后再加上一个,所以趋于稳定. 官方题解: 1 #include <iostream> 2 #include <cstdio> 3 #includ

HDU 4927 Series (找规律+JAVA)

题目链接:HDU 4927 Series 题意:给出一串N个元素的序列,作为第一串序列,第二串序列是第二串序列相邻元素的查值(即Bi=Ai+1-Ai)...第三串....一直到第N-1串是序列中只有一个数. 刚开始想到模拟一发,WA了一把,推出公式,发现是二项展开的系数(正负交替).组合数,果断要大数,苦逼JAVA不会.和一起队友摸索着,又T了一发,再想到组合数的递推.终于A了 C(a-1,b)=C(a,b)*a/(b-a+1) AC代码: import java.math.BigInteger

HDU 4919 打表找规律 java大数 map 递归

== oeis: 点击打开链接 瞎了,x.mod(BigInteger.ValueOf(2)).equal( BigInteger.ValueOf(1)) 写成了 x.mod(BigInteger.ValueOf(2)).equal( 1 ) T^T100块没了... import java.math.*; import java.util.*; import static java.lang.System.out; import java.io.*; public class Main { s

HDU 4990 Reading comprehension (找规律+矩阵快速幂)

题目链接:HDU 4990 Reading comprehension 题目给的一个程序其实就是一个公式:当N=1时 f[n]=1,当n>1时,n为奇数f[n]=2*f[n-1]+1,n为偶数f[n]=2*f[n-1]. 先不取模,计算前十个找规律.得到一个递推公式:f[n]=2*f[n-2]+f[n-1]+1 然后快速幂解决之. 给出一个神奇的网站(找数列通项):http://oeis.org/ AC代码: #include<stdio.h> #include<string.h&

hdu 5703 Desert(找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5703 Desert Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 177    Accepted Submission(s): 141 Problem Description A tourist gets lost in the dese