POJ 1995 快速幂模板
http://poj.org/problem?id=1995
简单的快速幂问题
要注意num每次加过以后也要取余,否则会出问题
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll mod_pow(ll x,ll n,ll mod)
{
ll res=;
while(n>)
{
if(n&) res=res*x%mod;
x=x*x%mod;
n>>=;
}
return res;
}
int main()
{
int i,j,z,h;
//freopen("in.txt","r",stdin);
ll num=,m,a,b;
scanf("%d",&z);
for(i=;i<=z;i++)
{
scanf("%lld%d",&m,&h);
for(j=;j<=h;j++)
{
scanf("%lld%lld",&a,&b);
num+=mod_pow(a,b,m);
num%=m;
}
cout<<num<<endl;num=;
}
return ;
}
POJ 1995 快速幂模板的更多相关文章
- Raising Modulo Numbers(POJ 1995 快速幂)
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5934 Accepted: ...
- poj 1995 快速幂
题意:给出A1,…,AH,B1,…,BH以及M,求(A1^B1+A2^B2+ … +AH^BH)mod M. 思路:快速幂 实例 3^11 11=2^0+2^1+2^3 => 3^1*3 ...
- POJ 1995 (快速幂) 求(A1B1+A2B2+ ... +AHBH)mod M
Description People are different. Some secretly read magazines full of interesting girls' pictures, ...
- POJ3070 矩阵快速幂模板
题目:http://poj.org/problem?id=3070 矩阵快速幂模板.mod写到乘法的定义部分就行了. 别忘了 I ( ) 和 i n i t ( ) 要传引用! #include< ...
- 89. a^b【快速幂模板】
a^b Description 求 aa 的 bb 次方对 pp 取模的值. 输入格式 三个整数 a,b,pa,b,p ,在同一行用空格隔开. 输出格式 输出一个整数,表示a^b mod p的值. 数 ...
- 矩阵快速幂模板(pascal)
洛谷P3390 题目背景 矩阵快速幂 题目描述 给定n*n的矩阵A,求A^k 输入输出格式 输入格式: 第一行,n,k 第2至n+1行,每行n个数,第i+1行第j个数表示矩阵第i行第j列的元素 输出格 ...
- hdu-1757 A Simple Math Problem---矩阵快速幂模板题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1757 题目大意: 求递推式第k项模m If x < 10 f(x) = x.If x > ...
- 51nod1113(矩阵快速幂模板)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1113 题意:中文题诶- 思路:矩阵快速幂模板 代码: #inc ...
- luoguP3390(矩阵快速幂模板题)
链接:https://www.luogu.org/problemnew/show/P3390 题意:矩阵快速幂模板题,思路和快速幂一致,只需提供矩阵的乘法即可. AC代码: #include<c ...
随机推荐
- lightbox图片展示效果
1.lightbox 头部导入: <script type="text/javascript" src="../Public/Js/prototype.js&quo ...
- Robot Framework--09 分支与循环的用法
转自:http://blog.csdn.net/tulituqi/article/details/8038923 一.分支 在Robotframework2.7.4之前的版本,我们要想写IF比较容易, ...
- LVS工作总结之原理篇–DR模式
原文地址: http://www.chenqing.org/2012/11/%E3%80%90lvs%E3%80%91lvs%E5%B7%A5%E4%BD%9C%E6%80%BB%E7%BB%93%E ...
- rpm 命令
这些事rpm的常用参数!!! 你可以在linux下man 一下rpm就知道了!!! 不过是英文的,不然你可以百度一下rpm就知道了额!!! 下面我帮你贴几个!!!!rpm 常用命令1.安装一个包 # ...
- Python基础之【第二篇】
一.作用域 对作用域来说,只要变量在内存里面存在就可以使用: ==: name = 'saneri' print name 二.三元运算 result = 值1 if 条件 else 值2 如果条件为 ...
- dubbo 教程
阿里巴巴dubbo主页:http://code.alibabatech.com/wiki/display/dubbo/Home-zh 1. Dubbo是什么? Dubbo是一个分布式服务框架,致力于提 ...
- PhpStorm 快捷键
不容易记住的: Ctrl + Shift + F 查找文本,在项目目录或指定的目录 Ctrl + Shift + R 查找文本并替换,在项目目录或指定的目录 Ctrl + E 打开最近关闭的 ...
- ASP.NET MVC Global.cs - 应用程序事件
一.Application_End Application_End:网站关闭,或重启时,会触发该方法 二.Application_Start 第一个访问网站的用户会触发该方法. 通常会在该 ...
- tomcat启动异常(严重: Dispatcher initialization failed Unable to load configuration. - [unknown location] )
严重: Dispatcher initialization failed Unable to load configuration. - [unknown location] at com.opens ...
- 【帖子】怎么彻底删除kafka的topic,然后重建?
怎么彻底删除kafka的topic,然后重建? 网上都说用kafka-run-class.shkafka.admin.DeleteTopicCommand 命令删除topic,但是并没有成功,用kaf ...