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. Delphi中TWebBrowser中注入Js

    最近帮朋友做一个软件,其中要自动化某网页中的操作,最简的操作是调用自己写的代码. 代码如下: procedure TForm1.Button2Click(Sender: TObject);var  i ...

  2. [Android]The connection to adb is down, and a severe error has occured.

    在Android开发时,有时我们开启虚拟机执行程序时.会报类似下面错误: [2015-07-19 15:08:29 - TestXiaoYanLibrary] The connection to ad ...

  3. 3.类型、值和变量-JavaScript权威指南笔记

    开始变得有意思起来了,然而第三章还是以基础知识了解的角度阐释相关的概念,并没有深入到结合代码以及要实现的功能讲用法和原理的程度. 1.概论. value:程序的运行是对值的操作. type:能够表示并 ...

  4. SQLSERVER常用脚本整理

    数据库存储空间查询(数据库的大小及数据库中各个表的数据量和每行记录大小) IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = Object_i ...

  5. MFC知识点整理

    1. 在使用VS2010生成基于MFC的应用程序时,在“Visual C++”下选择“MFC”,对话框中间区域会出现三个选项:MFC ActiveX Control.MFC Application和M ...

  6. C++中常用特殊符号简介(& , * , : , :: , ->)

    1."&"一般表示:引用,按位与,取地址. 如: class Complex { public: Complex operator+(Complex &c2) .. ...

  7. 2014.9.15HTML

    <html> <title> </title> ——页面标题 <head> </head> ——网页上的控制信息 <body> ...

  8. NXT项目准备资料

    聊天资源 http://www.cocoachina.com/ios/20150205/11116.html https://developer.layer.com/docs/ios/quick-st ...

  9. java堆溢出的小栗子

    package com.xiaoysec.test; import java.util.ArrayList; import java.util.List; /** *VM Args:-verbose: ...

  10. Linux学习之挂载

    linux的系统组织方式是——整个系统从根开始,按树形目录依次向下逐渐扩大,分类存放不同用途的文件,/读作“斜线”,英文slash:当其写作一个路径时,第一个/表示根,即root,其他的/表示路径分割 ...