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 ...
随机推荐
- decode-string(挺麻烦的)
Java String作为参数传参是不会改变的,这个与常识的感觉不同. public String decodeString(String s) { s = ""; return ...
- LA 3029 - City Game (简单扫描线)
题目链接 题意:给一个m*n的矩阵, 其中一些格子是空地(F), 其他是障碍(R).找一个全部由F 组成的面积最大的子矩阵, 输出其面积乘以3的结果. 思路:如果用枚举的方法,时间复杂度是O(m^2 ...
- sdut 2846 Remove Trees (二分 + 贪心)
题目 和poj 上的一道题几乎一样. 题意:已知n棵树距第一棵树的距离,求删掉m棵树后的 树之间 的最小距离 的最大值. 思路:二分枚举最小的距离,注意二分的写法. #include <ios ...
- 函数buf_page_get_gen
/********************************************************************//** This is the general functi ...
- BZOJ_1024_[SHOI2008]_生日快乐_(dfs)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1024 给出一个\(x*y\)的距形,要求平行于边切,最终切成\(n\)个面积相等的小距形,求长 ...
- BZOJ2151: 种树
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2151 题解:此题=数据备份.喜闻乐见挂链表. 代码: #include<cstdio&g ...
- 四种途径将HTML5 web应用变成android应用
作为下一代的网页语言,HTML5拥有很多让人期待已久的新特性.HTML5的优势之一在于能够实现跨平台游戏编码移植,现在已经有很多公司在移动 设备上使用HTML5技术.随着HTML5跨平台支持的不断增强 ...
- 使用Java VisualVM监控远程JVM
我们经常需要对我们的开发的软件做各种测试, 软件对系统资源的使用情况更是不可少, 目前有多个监控工具, 相比JProfiler对系统资源尤其是内存的消耗是非常庞大,JDK1.6开始自带的VisualV ...
- 为SQL表添加全文索引范例
--范例: --为HR_Job中的JobTitle,JobDes创建全文索引 execute sp_fulltext_catalog 'boli188', 'create' --创建全文目录,boli ...
- OutputCache缓存各参数的说明
Duration 缓存时间,以秒为单位,这个除非你的Location=None,可以不添加此属性,其余时候都是必须的. Location Location当被设置为None时,其余的任何设置将不起作用 ...