B - Raising Modulo Numbers
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 Ai
Bi 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
by the single positive integer Z appearing on the first line of input.
Then the assignements follow. Each assignement begins with line
containing an integer M (1 <= M <= 45000). The sum will be divided
by this number. Next line contains number of players H (1 <= H <=
45000). Next exactly H lines follow. On each line, there are exactly
two numbers Ai and Bi separated by space. Both numbers cannot be equal
zero at the same time.
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
题目大意:给一个M, 再给一个n表示接下来有n组数据(a,b) 计算a的b次幂,在将这n组数据加在一起。 然后对M求余。
快速幂求余,a^b%m=[(a%m)^b]%m
同余定理 (a+b+c...)%m=(a%m+b%m+c%m...)%m
AC代码:
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll m;//模
int pow(ll x,ll y)
{
ll res=;
while(y)
{
if(y&)
res=res*x%m;
x=x*x%m;
y>>=;
}
return res%m;//(a+b+c...)%m=(a%m+b%m+c%m..)%m
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll c;
scanf("%lld %lld",&m,&c);
ll a,b,sum=;
for(int i=;i<c;i++)
{
scanf("%lld %lld",&a,&b);
sum+=pow(a,b);
}
printf("%lld\n",sum%m); }
return ;
}
B - Raising Modulo Numbers的更多相关文章
- POJ1995 Raising Modulo Numbers
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6373 Accepted: ...
- poj 1995 Raising Modulo Numbers【快速幂】
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5477 Accepted: ...
- POJ1995 Raising Modulo Numbers(快速幂)
POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...
- 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: ...
- poj1995 Raising Modulo Numbers【高速幂】
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5500 Accepted: ...
- 【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: 5532 Accepted: ...
- Raising Modulo Numbers
Description People are different. Some secretly read magazines full of interesting girls' pictures, ...
- Day7 - J - Raising Modulo Numbers POJ - 1995
People are different. Some secretly read magazines full of interesting girls' pictures, others creat ...
随机推荐
- SpringBoot启动项目之后,访问页面出现Whitelabel Error Page
话说万事具备,只欠东风- 蹭闲暇时来跑个SpringBoot项目玩玩,把一切配置依赖准备就绪之后打算运行项目. Staring...... 接着,在浏览器输入地址 localhost:8080/hel ...
- Linux常用的命令收藏
摘要 Linux现在已经是大部分草根站长不可缺少的一部分,想要维护好你的网站就必须懂得常用的linux命令,这个可以加快你对服务器的维护,运营:同时Linux在嵌入式系统开发中有不可替代的优势,越来越 ...
- stm32CubeMx+TrueSTUDIO+uc/os-III移植开发(一)
自从接触到stm32cubemx后,发现使用起来很方便,用来做项目开发的话,由于是图形化操作界面,工作效率比较快.如果要学习操作系统,以前的IDE如keil,IAR等IDE对操作系统的代码调试起来不够 ...
- arcgis server10.7修改打印模板后前台调用不生效
在10.5.1及之前的版本中,如果更改打印地图模板,如字体设置,那么直接修改[ArcGIS for Server 安装目录]/Templates/ExportWebMapTemplates下的mxd的 ...
- SpringBoot 集成多数据源
一个项目中怎么划分数据库,可以通过具体业务需求. 项目中数据源怎么如何划分,通过注解的方式@Datasource(ref="") 在方法上指定,会连接指定的数据源,这种方式比较繁琐 ...
- Python python对象 deque
# deque对象 ''' class collections.deque([ iterable [,maxlen ] ] ) 返回一个从左到右(使用append())初始化的新deque对象,其中包 ...
- hive的基本操作与应用
通过hadoop上的hive完成WordCount 启动hadoop Hdfs上创建文件夹 创建文件夹 上传文件至hdfs 启动Hive 创建原始文档表 导入文件内容到表docs并查看 用HQL进行词 ...
- Js,JQuery不同方式绑定的同一事件可以同时触发,互不干扰
比如,onclick绑定,然后jquery.on("click", function(){})绑定等
- 【线段树基础】NKOJ 1321 数列操作
时间限制 : 10000 MS 空间限制 : 165536 KB 问题描述 假设有一列数{Ai}(1≤i≤n),支持如下两种操作:将Ak的值加D.(k, D是输入的数)输出As+As+1+…+At ...
- 树形DP——动态规划与数据结构的结合,在树上做DP
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是算法与数据结构的第15篇,也是动态规划系列的第4篇. 之前的几篇文章当中一直在聊背包问题,不知道大家有没有觉得有些腻味了.虽然经典的文 ...