POJ 1995 Raising Modulo Numbers(快速幂取模)
来源:互联网 发布:北京it外包 编辑:程序博客网 时间:2024/05/17 04:14
POJ1995
题目大意
有N个人,每个人给出两个数字a,b,求∑(Ai\^Bi) mod M。
Input
3
16
4
2 3
3 4
4 5
5 6
36123
1
2374859 3029382
17
1
3 18132
Output
2
13195
13
代码
#include <iostream>#include <cstdio>typedef long long LL;LL quick(LL a,LL b,int c){ LL ans=1; //记录结果 a=a%c; //预处理,使得a处于c的数据范围之下 while(b!=0) { if(b&1) ans=(ans*a)%c; //如果b的二进制位不是0,那么我们的结果是要参与运算的 b>>=1; //二进制的移位操作,相当于每次除以2,用二进制看,就是我们不断的遍历b的二进制位 a=(a*a)%c; //不断的加倍 } return ans;}int main(){ int t; int M,N,i; LL e,f; scanf("%d",&t); while(t--) { LL sum=0; scanf("%d%d",&M,&N); for(i=0;i<N;i++) { scanf("%lld%lld",&e,&f); sum+=quick(e,f,M); } sum%=M; printf("%lld\n",sum); } return 0;}
阅读全文
0 0
- POJ 1995 Raising Modulo Numbers 快速幂取模
- poj 1995 Raising Modulo Numbers 快速幂取模
- POJ 1995 Raising Modulo Numbers(快速幂取模)
- Raising Modulo Numbers (poj 1995 快速幂水题)
- POJ 1995 Raising Modulo Numbers【快速幂】
- poj 1995 Raising Modulo Numbers 【快速幂】
- POJ 1995:Raising Modulo Numbers 快速幂
- poj 1995 Raising Modulo Numbers【快速幂】
- POJ - 1995 Raising Modulo Numbers 【快速幂】
- |poj 1995|快速幂|Raising Modulo Numbers
- POJ.1995 Raising Modulo Numbers (快速幂)
- POJ 1995 Raising Modulo Numbers 快速幂
- Raising Modulo Numbers 【poj-1995】【快速幂】
- 【POJ 1995】Raising Modulo Numbers(快速幂)
- POJ 1995/ ZOJ 2150 : Raising Modulo Numbers - 快速幂取模
- Poj.1995 Raising Modulo Numbers【快速幂取模】 2015/04/22
- POJ 1995 Raising Modulo Numbers(快速幂取模)
- Raising Modulo Numbers 快速幂取模
- 宏以及#define;enum;comst的区别
- JAVA 8函数式编程(六):怎样复用Stream对象
- rbac权限管理初学
- C语言存储类
- mysql导出数据时提示错误1290(secure_file_priv)的解决办法
- POJ 1995 Raising Modulo Numbers(快速幂取模)
- java 字符串截取的几种方式
- [转]图像边缘提取-Canny算法
- 纯净:Linux目录结构
- JVM的内存分配
- github版本控制器入门必看的文章
- jQuery EasyUI中有关分页时,无法传递页码和大小到Controller
- HTML_内联SVG
- poj2528 Mayor’s posters(线段树+离散化)