杭电 4681
来源:互联网 发布:金特软件 编辑:程序博客网 时间:2024/06/05 05:06
Couple doubi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 743 Accepted Submission(s): 537
Problem 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).
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 320 3
Sample Output
YESNO
Author
FZU
Source
2014 Multi-University Training Contest 1
费马小定理 最终只需要判定k/(p-1)是否是奇数就行了
代码如下
#include<stdio.h>
int main()
{
int p,k,m;
while(~scanf("%d%d",&k,&p))
{
m=k/(p-1);
if(m&1)//if(m%2==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
int main()
{
int p,k,m;
while(~scanf("%d%d",&k,&p))
{
m=k/(p-1);
if(m&1)//if(m%2==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
0 0
- 杭电 4681
- 杭电
- 杭电
- 杭电
- 杭电 1234 和 杭电 2115
- 杭电2056之Rectangles 杭电
- 杭电ACM1061Rightmost Digit
- 杭电2099 7.11
- 杭电ACM 1003
- 杭电 ACM 2016
- 杭电ACM1466
- 杭电ACM1003
- 杭电ACM1225
- 杭电ACM2023
- 杭电ACM2602
- 杭电ACM2955
- 杭电ACM3198
- 杭电ACM2028 求教
- 数码机顶盒设置IP
- MTK6592平台 touchpanel驱动设备加载(二)
- Android App 内存泄露之Handler
- Java多线程的wait()和notify()例子
- 编译使用 libmp4v2库 libmp4v2.lib(atom_tkhd.obj) : error LNK2001: 无法解析的外部符号 _gettimeofday 错误解决办法.
- 杭电 4681
- 五大常用算法之一:分治算法
- Akka学习笔记(一):创建Hello World工程
- 从数组里挑出只出现一次的对象
- Android 版本解决
- 突然之间不能访问http://127.0.0.1 http://localhost/
- Android 入门开发指南之一 -- Hello,Android例子
- 五大常用算法之二:动态规划算法
- 使用jxl导出大数据量EXCEL时内存溢出的解决办法