POJ1995 Raising Modulo Numbers
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 6373 | Accepted: 3760 |
Description
Each player chooses two numbers Ai and Bi and writes them on a slip of paper. Others cannot see the numbers. In a given moment all players show their numbers to the others. The goal is to determine the sum of all expressions AiBi from all players including oneself and determine the remainder after division by a given number M. The winner is the one who first determines the correct result. According to the players' experience it is possible to increase the difficulty by choosing higher numbers.
You should write a program that calculates the result and is able to find out who won the game.
Input
Output
(A1B1+A2B2+ ... +AHBH)mod M.
Sample Input
3
16
4
2 3
3 4
4 5
5 6
36123
1
2374859 3029382
17
1
3 18132
Sample Output
2
13195
13
Source
快速幂裸题,暴力算的话会TLE。
//快速幂
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int Z,M;
int n;
int sum;
int a,b;
int ksm(int a,int b){
int now=a%M;
int res=;
while(b){
if(b&)res=res*now%M;
now=now*now%M;
b>>=;
}
return res;
}
int main(){
scanf("%d",&Z);
while(Z--){
sum=;
scanf("%d",&M);
scanf("%d",&n);
int i,j;
for(i=;i<=n;i++){
scanf("%d%d",&a,&b);
sum=(sum+ksm(a,b))%M;//累加
}
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 ...
- poj1995 Raising Modulo Numbers【高速幂】
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5500 Accepted: ...
- POJ1995:Raising Modulo Numbers(快速幂取余)
题目:http://poj.org/problem?id=1995 题目解析:求(A1B1+A2B2+ ... +AHBH)mod M. 大水题. #include <iostream> ...
- 【POJ - 1995】Raising Modulo Numbers(快速幂)
-->Raising Modulo Numbers Descriptions: 题目一大堆,真没什么用,大致题意 Z M H A1 B1 A2 B2 A3 B3 ......... AH ...
- poj 1995 Raising Modulo Numbers【快速幂】
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5477 Accepted: ...
- Raising Modulo Numbers(POJ 1995 快速幂)
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5934 Accepted: ...
- poj 1995 Raising Modulo Numbers 题解
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6347 Accepted: ...
- POJ 1995:Raising Modulo Numbers 快速幂
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5532 Accepted: ...
- POJ1995:Raising Modulo Numbers
二进制前置技能:https://www.cnblogs.com/AKMer/p/9698694.html 题目传送门:http://poj.org/problem?id=1995 题目就是求\(\su ...
随机推荐
- 查看和设置oracle数据库的最大连接数
当前的连接数 select count(*) from v$process; 设置的最大连接数(默认值为150) select value from v$parameter where name = ...
- 转:CentOS设置时区
from: http://os.51cto.com/art/201004/192805.htm 建议直接使用: 1. session 临时修改查看: tzselect. 然后数字键入,回车 2. 永久 ...
- mysql数据库误删除后的数据恢复操作说明
在日常运维工作中,对于mysql数据库的备份是至关重要的!数据库对于网站的重要性使得我们对mysql数据的管理不容有失!然后,是人总难免会犯错误,说不定哪天大脑短路了来个误操作把数据库给删除了,怎么办 ...
- [Usaco2008 Nov]mixup2 混乱的奶牛 简单状压DP
1231: [Usaco2008 Nov]mixup2 混乱的奶牛 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 685 Solved: 383[S ...
- C语言 后缀自增的优先级详解
// ++ 后缀自增与取地址& ,提领 * (指针里的操作符)的优先级比较 #include<stdio.h> #include<stdlib.h> #include& ...
- GO To Definition的背后操作【VS2015 C#】
使用VS开发U3D项目时,去察看某个变量的声明,比如某组件的gameObject变量,会看到如下代码 一看似乎有点晕,这代码什么意思啊,就一个 public GameObject gameObject ...
- [转]World Wind学习总结一
WW的纹理,DEM数据,及LOD模型 以earth为例 1. 地形数据: 默认浏览器纹理数据存放在/Cache/Earth/Images/NASA Landsat Imagery/NLT Landsa ...
- JS案例之5——移动端触屏滑动
移动端触屏滑动的效果其实就是图片轮播,在PC的页面上很好实现,绑定click和mouseover等事件来完成.但是在移动设备上,要实现这种轮播的效果,就需要用到核心的touch事件.处理touch事件 ...
- 构建高转化率的着陆页-PS+HTML+网络营销
课程简介 本课程是全网独家专业的着陆页课程,课程完整的再现了整个着陆页实战案例的开发过程,包括:策划.设计和实现.上线后的推广.优化及提高转化率的技巧等,本套课程能帮助您迅速掌握着陆页的能力,迅速洞察 ...
- 用python简单处理图片(5):图像直方图
我们先来看两个函数reshape和flatten: 假设我们先生成一个一维数组: vec=np.arange(15) print vec 显示为: [ 0 1 2 3 4 5 6 7 8 9 10 1 ...