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).
 
Output
For each line, output an integer, as described above.
 
Sample Input
2 3
20 3
 
Sample Output
YES
NO
 
Source
 
Recommend
We have carefully selected several similar problems for you:  4871 4870 4869 4868 4867 
 
没听过什么费马定理,就仅仅知道这:


卧槽,就这样勉强写的,哎,说多了都是泪。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; long long k,p;
int main()
{
while(~scanf("%I64d%I64d",&k,&p))
{
int s=0;
if(p==2)
{
if(((k+1)/2%2))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
continue;
}
s=k/(p-1);
if(s%2)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}

事实上仅仅要这样。。。


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; long long k,p;
int main()
{
while(~scanf("%I64d%I64d",&k,&p))
{
int s=k/(p-1);
if(s%2)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}

我小学没毕业,干只是那些高中生。。

最新文章

  1. .net自带的IOC容器MEF使用
  2. Android 蓝牙
  3. 16个基本颜色关键字 Basic color keywords
  4. thoughtworks编程题
  5. 【转】HTTP POST GET 本质区别详解
  6. 使用“原生”HTML DOM获取input的输入值并显示
  7. Oracle连接的若干错误
  8. 移动端动画使用transform提升性能
  9. MatlabR2014a 安装破解详细图文教程(附下载链接(内附CVX工具箱))
  10. Canvas_2
  11. diy toy: image auto-handler
  12. springBoot系列教程08:拦截器(Interceptor)的使用
  13. torch分类问题
  14. centos7下安装Go环境
  15. UOJ176 新年的繁荣
  16. Python基础6 面向对象
  17. MailBee.NET
  18. nagios系列(四)之nagios主动方式监控tcp常用的80/3306等端口监控web/syncd/mysql及url服务
  19. Spring事务管理详解_基本原理_事务管理方式
  20. Oracle初级第一天

热门文章

  1. python3 序列
  2. 4、linux开发中常用指令
  3. 修复STS4 server中没有Tomcat的问题(必看,官方推荐,包教包会,国内首发)
  4. [Angular] Creating an Observable Store with Rx
  5. #308 (div.2) B. Vanya and Books
  6. arm cpu的架构及分类说明
  7. C语言学习笔记:12_变量的存储方式和生存期
  8. Android中密码输入内容可见性切换
  9. Android 多个Fragment嵌套导致的三大BUG
  10. Android 自定义View——自定义点击事件