嗯...

题目链接:http://poj.org/problem?id=1995

快速幂模板...

AC代码:

 #include<cstdio>
#include<iostream> using namespace std; int main(){
long long N, M, n, a, b, c, sum = ;
scanf("%lld", &N);
while(N--){
scanf("%lld%lld", &M, &n);
sum = ;
for(int i = ; i <= n; i++){
c = ;
scanf("%lld%lld", &a, &b);
while(b){
if(b & ) c = c * a % M;
a = a * a % M;
b /= ;
}
sum += c % M;
}
printf("%lld\n", sum % M);
}
return ;
}

AC代码

POJ 1995 Raising Modulo Numbers(快速幂)的更多相关文章

  1. POJ 1995 Raising Modulo Numbers (快速幂)

    题意: 思路: 对于每个幂次方,将幂指数的二进制形式表示,从右到左移位,每次底数自乘,循环内每步取模. #include <cstdio> typedef long long LL; LL ...

  2. POJ 1995:Raising Modulo Numbers 快速幂

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5532   Accepted: ...

  3. poj 1995 Raising Modulo Numbers【快速幂】

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5477   Accepted: ...

  4. POJ1995 Raising Modulo Numbers(快速幂)

    POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...

  5. poj 1995 Raising Modulo Numbers 题解

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6347   Accepted: ...

  6. POJ 1995 Raising Modulo Numbers 【快速幂取模】

    题目链接:http://poj.org/problem?id=1995 解题思路:用整数快速幂算法算出每一个 Ai^Bi,然后依次相加取模即可. #include<stdio.h> lon ...

  7. POJ 1995 Raising Modulo Numbers

    快速幂取模 #include<cstdio> int mod_exp(int a, int b, int c) { int res, t; res = % c; t = a % c; wh ...

  8. ZOJ2150 Raising Modulo Numbers 快速幂

    ZOJ2150 快速幂,但是用递归式的好像会栈溢出. #include<cstdio> #include<cstdlib> #include<iostream> # ...

  9. POJ1995:Raising Modulo Numbers(快速幂取余)

    题目:http://poj.org/problem?id=1995 题目解析:求(A1B1+A2B2+ ... +AHBH)mod M. 大水题. #include <iostream> ...

随机推荐

  1. tomcat8.5和redis实现session共享

    1. 问题 ​ 由于之前看其他资料配置的session共享没注意自己tomcat的版本所以出现了诸多问题,tomcat8.5和之前版本的配置是不一样的. 2. 配置 ​ ①将如图所示三个jar包放入t ...

  2. 解决jmeter 24h长时间压测-o生成报告文件达到几个g以及以上的问题

    问题描述:jmeter执行稳定性测试时,因时间过长,导致jtl文件过大,生成html报告过程报内存溢出错误(增加内存配置也不能解决) 使用 jmeter -n -t    test.jmx   -l  ...

  3. html+css 文本折叠

    先看效果: 收缩状态 展开状态 源代码: <!doctype html> <html lang="zh"> <head> <meta ch ...

  4. B1027 打印沙漏

    题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805294251491328 1027 打印沙漏 (20 分) ...

  5. angular 读写电脑本地文件

    angular 读写本地电脑文件 angular将数据写进到电脑文件 在前端写一个按钮,然后点击按钮的时候在本地电脑保存一个text文件. 这时候我们需要用到一个angular的插件,叫做" ...

  6. EAC3 channel & program extension

    EAC3 bit stream syntax允许在single bitstream中存在time-multiplexed substreams. 在EAC3的signle bitstream中,允许s ...

  7. 免费天气API,天气JSON API,不限次数获取十五天的天气预报

    紧急情况说明: 禁用IP列表: 39.104.69.*(原因39.104.69.6 在2018年10月的 17~20日 排行为top 1,每天几十万次.) 47.98.211.* (原因47.98.2 ...

  8. 百炼OJ - 1002 - 方便记忆的电话号码

    题目链接 思路 开个一千万的数组计数,最后遍历即可. #include<stdio.h> #include<string.h> #include<algorithm> ...

  9. bistoury的源码启动(二)

    bistoury.conf这个东东就是我们代码中的 -Dbistoury.conf=D:\openSource\bistoury\bistoury-proxy\conf 这样就能搞定了,一下子就能启动 ...

  10. 联想ideapad关闭Fn

    1.打开bios 开启/重启电脑的时候长按Fn+F2,就可以打开bios面板 2.切换到configuration菜单 使用键盘的右箭头将切换到configuration 3.关闭Fn 使用键盘下箭头 ...