HDU 5666 Segment(快速乘法/快速幂改)
2016-04-17 09:24
302 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5666
代码:
代码:
#include<stdio.h> #include<string.h> using namespace std; int main() { int t; scanf("%d",&t); while(t--) { __int64 q,p; scanf("%I64d%I64d",&q,&p); __int64 ans=0,a=q-1,b=q-2; if(b%2==0) //规律是(q-1)*(q-2)/2; b=b/2; else<span style="white-space:pre"> </span>//讨论<span style="font-family: Arial, Helvetica, sans-serif;">(q-1)与(q-2)的奇偶,</span>
a=a/2; while(b) { if(b%2==1) ans=(ans+a)%p; b=(b/2)%p; a=(a+a)%p; } printf("%I64d\n",ans); } }
相关文章推荐
- 《原创》网络版五子棋node.js+websocket
- 19.JAVA编程思想——使用Maps
- 18.JAVA编程思想——使用Sets
- C#——找出实现某个接口的所有类
- Swift中文教程(三) 字符串和字符
- pycharm快捷键及一些常用设置
- 17.JAVA编程思想——使用Lists
- ZOJ 3513 Human or Pig
- 16.JAVA编程思想——使用Collections
- 15.JAVA编程思想——新集合
- emgucv——findContours
- 分布式服务框架 Zookeeper -- 管理分布式环境中的数据
- 14.JAVA编程思想——通用集合库
- CF #347 (Div.2) B. Rebus(贪心)
- 进程间通信(4)---最高效的进程间通信方式--内存共享
- 13.JAVA编程思想——排序
- LSB的JAVA实现,随便写写,也不知道有什么用0.0
- 用 Python 和 OpenCV 检测图片上的条形码
- 那些年,学swift踩过的坑
- JS组件Bootstrap dropdown组件扩展hover事件