POJ1995:Raising Modulo Numbers(快速幂取余)
题目:http://poj.org/problem?id=1995
题目解析:求(A1B1+A2B2+ ... +AHBH)mod M.
大水题。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
int n,mod,sum;
int main()
{
int T,a[],b[];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&mod,&n);
int sum=,t;
for(int i=; i<n; i++)
{
scanf("%d%d",&a[i],&b[i]);
t=;
while(b[i])
{
if(b[i]&)
t=(t*a[i])%mod;
b[i]>>=;
a[i]=((a[i]%mod)*(a[i]%mod))%mod;
}
sum=(sum+t)%mod;
}
printf("%d\n",sum);
}
return ;
}
POJ1995:Raising Modulo Numbers(快速幂取余)的更多相关文章
- POJ1995 Raising Modulo Numbers(快速幂)
POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...
- POJ 1995:Raising Modulo Numbers 快速幂
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5532 Accepted: ...
- Raising Modulo Numbers_快速幂取模算法
Description People are different. Some secretly read magazines full of interesting girls' pictures, ...
- ZOJ2150 Raising Modulo Numbers 快速幂
ZOJ2150 快速幂,但是用递归式的好像会栈溢出. #include<cstdio> #include<cstdlib> #include<iostream> # ...
- POJ 1995 Raising Modulo Numbers (快速幂)
题意: 思路: 对于每个幂次方,将幂指数的二进制形式表示,从右到左移位,每次底数自乘,循环内每步取模. #include <cstdio> typedef long long LL; LL ...
- 洛谷 P1226 【模板】快速幂||取余运算
题目链接 https://www.luogu.org/problemnew/show/P1226 题目描述 输入b,p,k的值,求b^p mod k的值.其中b,p,k*k为长整型数. 输入输出格式 ...
- hdu1061Rightmost Digit(快速幂取余)
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- LightOJ - 1282 - Leading and Trailing(数学技巧,快速幂取余)
链接: https://vjudge.net/problem/LightOJ-1282 题意: You are given two integers: n and k, your task is to ...
- poj1995 Raising Modulo Numbers【高速幂】
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5500 Accepted: ...
随机推荐
- Ocx控件注册不成功?可能是tlb文件导致~
Ocx文件是最常用的文件,实际操作中常常需要注册之~ 但是问题来了,经常会出现注册不成功的问题: 解决方法: 1.以“管理员身份”注册 2.Dependency Walker查看依赖是否缺失 3.查看 ...
- mysql通过mysql_install_db初始化数据目录时使用--user选项的作用是什么?
需求描述: mysql数据库通过mysql_install_db初始化数据目录时,使用了--user选项,这里记录下该参数的作用 参数解释: 1.--user的作用:就是以哪个操作系统用户来执行mys ...
- go在线图书
https://books.studygolang.com/The-Golang-Standard-Library-by-Example/
- nginx 杂谈
http://blog.sina.com.cn/s/articlelist_1834459124_0_1.html
- 微信jssdk批量添加卡券接口(踩坑经验)
1)首先是官方接口文档: 1.批量添加卡券接口:https://mp.weixin.qq.com/wiki?action=doc&id=mp1421141115&t=0.0861973 ...
- 查看磁盘读写:iotop
iotop命令用来动态地查看磁盘IO情况,用法如下: [root@localhost ~]$ yum install -y iotop # 安装iotop命令 [root@localhost ~]$ ...
- linux mysql添加用户,删除用户,以及用户权限
一些主要的命令: 登录: mysql -u username -p 显示全部的数据库: show databases; 使用某一个数据库: use databasename; 显示一个数据库的全部表: ...
- c#截取图片
简单的保存数据流 <input name="upImg" style="width: 350px; height: 25px;" size="3 ...
- 【markdown】使用 js 实现自己得markdown 网页编辑器
首先从这里下载其浏览器版: https://github.com/evilstreak/markdown-js/releases 解压缩后在其js文件同目录下新建一个网页进行测试,代码如下: < ...
- LNMP ftp 可以登录无权限操作?
服务器环境: LNMP ftp : LNMP ftp一键安装 嘛卖批啊! 解决办法: 登录服务器.执行以下命令 chattr -i /home/wwwroot/default/.user.ini c ...