Day7 - J - Raising Modulo Numbers POJ - 1995
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
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
思路:题目一大串,有用的就是output(, 裸的欧拉降幂,直接打表求欧拉函数直接算即可(扩展欧拉)
typedef long long LL;
typedef pair<LL, LL> PLL; const int maxm = ; int phi[maxm]; void getEuler() {
phi[] = ;
for(int i = ; i < maxm; ++i) {
if(!phi[i]) {
for(int j = i; j < maxm; j += i) {
if(!phi[j]) phi[j] = j;
phi[j] = phi[j] / i * (i - );
}
}
}
} LL quick_pow(LL a, LL b, LL p) { //a^b(modp)
LL ret = ;
while(b) {
if(b&) ret = (ret * a) % p;
a = (a * a) % p;
b >>= ;
}
return ret;
} int main() {
int T, H;
getEuler();
LL MOD, A, B;
scanf("%d", &T);
while(T--) {
scanf("%lld", &MOD);
LL ans = ;
scanf("%d", &H);
for(int i = ; i < H; ++i) {
scanf("%lld%lld", &A, &B);
if(B < phi[MOD])
ans = (ans + quick_pow(A, B, MOD)) % MOD;
else
ans = (ans + quick_pow(A, B%phi[MOD]+phi[MOD], MOD)) % MOD;
}
printf("%lld\n", ans);
}
return ;
}
Day7 - J - Raising Modulo Numbers POJ - 1995的更多相关文章
- Mathematics:Raising Modulo Numbers(POJ 1995)
阶乘总和 题目大意:要你算一堆阶乘对m的模... 大水题,对指数二分就可以了... #include <iostream> #include <functional> #inc ...
- 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 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: ...
- POJ1995 Raising Modulo Numbers
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6373 Accepted: ...
- 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: ...
随机推荐
- Python 爬取 热词并进行分类数据分析-[热词分类+目录生成]
日期:2020.02.04 博客期:143 星期二 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] 所有相关跳转: a.[简单准备] b.[云图制作+数据导入] c.[ ...
- 常用FTP命令汇总
FTP是File Transport Protocol的简称,其作用是使连接到服务器上的客户可以在服务器和客户机间传输文件.除WWW服务外,FTP也算是使用最广泛的一种服务了.在cmd中ftp命令很多 ...
- 小程序云开发使用where查询遇到的问题
想用小程序云开发的where查询,结果不论输入什么都是不报错,开始没注意,后来发现输入数据库中有的数据时,给打印出来查询成功,输入数据库中没有的数据时,也会得到一个集合,只不过这个集合的长度为0而已. ...
- 一起探讨Go 语言为什么能成功?
导读 两位创造者Rob Pike和Robert Griesemer一起探讨了Go成功的原因. 常言道,历史不会重演,但总会惊人的相似. 如果您想创建一种编程语言,多向那些有经验的人士学习,他们有很多可 ...
- 第5节 Actor实战:1 - 6
10.3. Actor实战 10.3.1. 第一个例子 怎么实现actor并发编程: 1.定义一个class或者是object继承Actor特质,注意导包import scala.actor ...
- spring SpEL--转
原文:http://www.tuicool.com/articles/Jbq2QnM 概要: Spring表达式语言:SpEL Spring表达式语言 (简称 SpEL ):是一个 支持运行时查询和操 ...
- MySQL数据库索引:索引介绍和使用原则
本篇目录: 一.数据页与索引页 二.聚簇索引与非聚簇索引 三.唯一索引 四.索引的创建 五.索引的使用规则 六.数据库索引失效情况 本篇正文: 一.数据页与索引页 数据库的表存储分为数据页存储和索引页 ...
- Spring MVC中的ResponseEntity和ResponseBody的区别
1.ResponseEntity的优先级高于@ResponseBody. 在不是ResponseEntity的情况下才去检查有没有@ResponseBody注解. 如果响应类型是ResponseEnt ...
- [Write-up]-pwnlab_init
关于 下载地址点我 Flag: /root/flag.txt 放假的第一天 哔哩哔哩视频 信息收集 nmap -sn 192.168.7.1/24 Starting Nmap 7.01 ( https ...
- windows下hashcat利用GPU显卡性能破解密码
由于一般密码破解工具的破解速度实在是太慢,而且支持的密码破解协议也不多,暴力破解的话,有的密码1年时间也破不出来,用字典跑的话必须要明文密码在字典里才行,而且密码字典太大的话,也很浪费时间,跑不出来也 ...