HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi
题目链接:
http://acm.hust.edu.cn/vjudge/contest/121334#problem/D
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 1i+2i+...+(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
题意:
有n个数字定义如下:
num[i] = 1i+2i+...+(p-1)^i (mod p); (p是素数)
两人以最优策略轮流取其中的数字,总和大者获胜.
题解:
题目要求的数据规模非常大,下意识先打表找规律(注意p是素数).
很容易看出规律:每隔p-1个数才有一个非零数(易证该数为p-1);
由于是博弈的过程,所以每次都会取非零数; 判断非零数数目的奇偶即可.
数论解法:(费马小定理)
结论: (a^b)%p == ((a(p-1))(b/p-1))%p; 前提:b|p-1时才能用;
官方题解(2014 Multi-University Training Contest 1):
#
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 2100
#define mod 100000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int main(int argc, char const *argv[])
{
//IN;
LL k,p;
while(scanf("%I64d %I64d", &k, &p) != EOF)
{
LL ans = k / (p-1);
if(ans & 1) puts("YES");
else puts("NO");
}
return 0;
}
HDU 4861 Couple doubi (数论 or 打表找规律)的更多相关文章
- hdu 4861 Couple doubi(数论)
题目链接:hdu 4861 Couple doubi 题目大意:两个人进行游戏,桌上有k个球,第i个球的值为1i+2i+⋯+(p−1)i%p,两个人轮流取,假设DouBiNan的值大的话就输出YES, ...
- HDU 4919 Exclusive or (数论 or 打表找规律)
Exclusive or 题目链接: http://acm.hust.edu.cn/vjudge/contest/121336#problem/J Description Given n, find ...
- hdu 5391 Zball in Tina Town(打表找规律)
问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...
- HDU 4861 Couple doubi(找规律|费马定理)
Couple doubi Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- 数学--数论--HDU - 6124 Euler theorem (打表找规律)
HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the ...
- 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)
Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
随机推荐
- Linux 线程属性函数总结
1.初始化一个线程对象的属性 int pthread_attr_init(pthread_attr_t *attr); 返回值:若是成功返回0,否则返回错误的编号 形 参: attr 指向一个线程属性 ...
- poj 2886 Who Gets the Most Candies?(线段树和反素数)
题目:http://poj.org/problem?id=2886 题意:N个孩子顺时针坐成一个圆圈且从1到N编号,每个孩子手中有一张标有非零整数的卡片. 第K个孩子先出圈,如果他手中卡片上的数字A大 ...
- char型变量中能存贮一个中文汉字
char型变量是用来存储Unicode编码的字符的,unicode编码字符集中包含了汉字,所以,char型变量中当然可以存储汉字啦.不过,如果某个特殊的汉字没有被包含在unicode编码字符集中,那么 ...
- UVa 11330 (置换 循环的分解) Andy's Shoes
和UVa11077的分析很类似. 我们固定左脚的鞋子不动,然后将右脚的鞋子看做一个置换分解. 对于一个长度为l的循环节,要交换到正确位置至少要交换l-1次. #include <cstdio&g ...
- js对联广告代码,兼容性高
var browser = { ie6: function () { return ((window.XMLHttpRequest == undefined) && (ActiveXO ...
- BZOJ 1861 书架
(╯-_-)╯╧╧ 此处为错误代码. #include<iostream> #include<cstdio> #include<cstring> #include& ...
- 原创:js代码, 让dedecms支持Tag选择, 添加内容更为方便,不用手输Tag
dedecms在编辑修改内容时,TAG标签需要手动输,中文的Tag, 中间还得用半角字符','分隔, 输入法切来切去很不方便, 于是动手改后台代码, 利用后台的tags_main.php, 让d ...
- LeetCode Triangle 三角形(最短路)
题意:给一个用序列堆成的三角形,第n层的元素个数为n,从顶往下,每个元素可以选择与自己最近的两个下层元素往下走,类似一棵二叉树,求最短路. [], [,4], [6,,7], [4,,8,3] 注意: ...
- java 错误:找不到或无法加载主类的解决办法
此类错误的常见解决办法: 1.是因为.java文件不在项目的src路径内,也就是说源代码未被eclipse编译,字节码不存在无法运行了在项目名上右键 -> Builder Path -> ...
- 庖丁解牛-----Live555源码彻底解密(RTP打包)
本文主要讲解live555的服务端RTP打包流程,根据MediaServer讲解RTP的打包流程,所以大家看这篇文章时,先看看下面这个链接的内容; 庖丁解牛-----Live555源码彻底解密(根据M ...