Couple doubi

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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[];
while(scanf("%d%d",&k,&p)!=EOF)
{
memset(value,,sizeof(value));
for(int i=;i<=k;i++)
{
for(int j=;j<p;j++){
value[i]=(int)(value[i]+pow(j,i))%p;
}
printf("%d ",value[i]);
}
printf("\n");
}
return ;
}
/*
打表找了下规律,发现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-))%==)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
//费马定理神马看这里吧!
http://blog.csdn.net/u011439796/article/details/38048963

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

  1. hdu 4861 Couple doubi (找规律 )

    题目链接 可以瞎搞一下,找找规律 题意:两个人进行游戏,桌上有k个球,第i个球的值为1i+2i+⋯+(p−1)i%p,两个人轮流取,如果DouBiNan的值大的话就输出YES,否则输出NO. 分析:解 ...

  2. hdu 4861 Couple doubi(数论)

    题目链接:hdu 4861 Couple doubi 题目大意:两个人进行游戏,桌上有k个球,第i个球的值为1i+2i+⋯+(p−1)i%p,两个人轮流取,假设DouBiNan的值大的话就输出YES, ...

  3. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

  4. hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!

    http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE,  更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...

  5. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  6. HDU 5703 Desert (找规律)

    题意:一杯水有n的容量,问有多少种方法可以喝完. 析:找规律,找出前几个就发现规律了,就是2的多少次幂. 代码如下: #include <cstdio> #include <stri ...

  7. hdu 4952 Number Transformation (找规律)

    题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值, ...

  8. hdu 5241 Friends(找规律?)

    Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  9. HDU 4279 Number(找规律)

    Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

随机推荐

  1. SQL Server 启用与禁止触发器

    启用: disable trigger trigger_name on {objectName | database_name | server}; 禁用: enable trigger trigge ...

  2. openstack 开发step-by-step

    Set up your Open Stack There are several ways to deploy openstack, Devstack is easily for developer ...

  3. Boost::Thread使用示例 - CG-Animation - 博客频道 - CSDN.NET

    Boost::Thread使用示例 - CG-Animation - 博客频道 - CSDN.NET Boost::Thread使用示例 分类: C/C++ 2011-07-06 14:48 5926 ...

  4. 去英国Savile Row 做件私人定制手工西装_GQ男士网

    去英国Savile Row 做件私人定制手工西装_GQ男士网 去英国Savile Row 做件私人定制手工西装

  5. B. Wet Shark and Bishops(思维)

    B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. 解决.net中截取字符串的汉字与数字还有静态扩展方法

      转载 http://blog.163.com/cn_dreamgo/blog/static/52679452200961033212407/ 这两天在C#编程中应用到C#代码与C的代码信息交互,但 ...

  7. VBA 开发学习--基础语法3

    VBA字符串函数列表 Trim(string) 去掉string左右两端空白 Ltrim(string) 去掉string左端空白 Rtrim(string) 去掉string右端空白 Len(str ...

  8. javaScript 工作必知(七) 对象继承

    对象继承inherit var o = { r: 1 }; var c = function f() { }; c.prototype = o; c.r = 3; alert(o.r);//被继承的属 ...

  9. Oracle操作数据库oracleHelper

    1 Oracle OracleHelper //============================================================================ ...

  10. Chain of Responsibility模式

    熟悉VC/MFC的都知道,VC是“基于消息,事件驱动”,消息在VC开发中起着举足轻重的作用.MFC提供了消息的处理的链式处理策略,处理消息的请求将沿着预定好的路径依次进行处理.消息的发送者并不知道该消 ...