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 ...
随机推荐
- [BFS,A*,k短路径] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 path (Problem - 6705)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6705 path Time Limit: 2000/2000 MS (Java/Others) Mem ...
- 检测页面是否允许使用Flash
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 从源码和doc揭秘——Java中的Char究竟几个字节,Java与Unicode的关系
#编码与字符编码 (懂编码的建议直接跳过) 在计算机世界中,任何事物都是用二进制图片数字表示的,图片可以编码为JPG,PNG格式的字节流,音频,视频有MP3,MP4格式的字节流.这些JPG,MP3等都 ...
- Idea无法调出搜狗等中文输入法
在用户目录下的文件.xprofile 中添加一下内容 export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export XMODIFIERS=“@ ...
- cookie sessionStorage localStorage 使用小结
1.cookie 随http 一起发送 2.webStorage 客户端本地存储功能 可以在客户端 本地建立 一个数据库 不参与与服务器的通讯 setItem (key, value) —— 保存 ...
- coding++:win10家庭版升级专业版方案
win10家庭版升级专业版密钥: VK7JG-NPHTM-C97JM-9MPGT-3V66T 4N7JM-CV98F-WY9XX-9D8CF-369TT FMPND-XFTD4-67FJC-HDR8C ...
- Thread Future模式
多线程不管是extends Thread 还是 implements Runnable 都是要重写run 方法来实现,这两种方式子线程都没有返回值. 如果要实现主线程对子线程的监听,让子线程有返回值, ...
- 已知IP地址和子网掩码求出网络地址、广播地址、地址范围和主机数(转载https://blog.csdn.net/qq_39026548/article/details/78959089)
假设IP地址为128.11.67.31,子网掩码是255.255.240.0.请算出网络地址.广播地址.地址范围.主机数.方法:将IP地址和子网掩码转化成二进制形式,然后进行后续操作. IP地址和子网 ...
- class-dump的安装和使用
安装步骤 1.下载地址:http://stevenygard.com/projects/class-dump/ 2.打开终端输入 open /usr/local/bin 3.把dmg文件中的class ...
- Python操作JSON数据代码示例
#!/usr/bin/env python import json import os def json_test(): return_dic = {} json_data = { 'appid':' ...