Raising Modulo Numbers(POJ 1995 快速幂)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 5934 | Accepted: 3461 |
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 //Z
16 //m
4 //h
2 3 h个a,b;
3 4
4 5
5 6 //计算(A1B1+A2B2+ ... +AHBH)mod M.
36123
1
2374859 3029382
17
1
3 18132
Sample Output
2
13195
13
快速幂模板题
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
#define Max 45000+10
LL a[Max],b[Max];
int m,h;
LL ans;
int mod_pow(int num,int n)
{
num=num%m;
LL res=;
while(n>)
{
if(n&)
res=res*num%m;
num=num*num%m;
n>>=;
}
return res;
}
int main()
{
int z;
int i,j;
freopen("in.txt","r",stdin);
scanf("%d",&z);
while(z--)
{
ans=;
scanf("%d%d",&m,&h);
// cout<<m<<" "<<h<<endl;
for(i=;i<h;i++)
scanf("%lld%lld",&a[i],&b[i]);
for(i=;i<h;i++)
{
ans+=mod_pow(a[i],b[i]);
ans=ans%m;
}
printf("%d\n",ans%m);
}
}
Raising Modulo Numbers(POJ 1995 快速幂)的更多相关文章
- Day7 - J - Raising Modulo Numbers POJ - 1995
People are different. Some secretly read magazines full of interesting girls' pictures, others creat ...
- Mathematics:Raising Modulo Numbers(POJ 1995)
阶乘总和 题目大意:要你算一堆阶乘对m的模... 大水题,对指数二分就可以了... #include <iostream> #include <functional> #inc ...
- POJ 1995 快速幂模板
http://poj.org/problem?id=1995 简单的快速幂问题 要注意num每次加过以后也要取余,否则会出问题 #include<iostream> #include< ...
- poj 1995 快速幂
题意:给出A1,…,AH,B1,…,BH以及M,求(A1^B1+A2^B2+ … +AH^BH)mod M. 思路:快速幂 实例 3^11 11=2^0+2^1+2^3 => 3^1*3 ...
- POJ 1995 (快速幂) 求(A1B1+A2B2+ ... +AHBH)mod M
Description People are different. Some secretly read magazines full of interesting girls' pictures, ...
- 【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: ...
- POJ 1995 Raising Modulo Numbers(快速幂)
嗯... 题目链接:http://poj.org/problem?id=1995 快速幂模板... AC代码: #include<cstdio> #include<iostream& ...
- poj 1995 Raising Modulo Numbers【快速幂】
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5477 Accepted: ...
随机推荐
- 自定义Filter服务
自定义一个用户Email长度超过12个字符后值截取前12个然后添加“...”显示. 例如: index.html <!DOCTYPE html> <html ng-app=" ...
- Could not open a connection to your authentication agent
执行ssh-add ~/.ssh/rsa 就会遇到上述错误了 解决方案: 先执行 eval `ssh-agent` (是-键上的那个`) 再执行 ssh-add ~/.ssh/rsa成功 ssh ...
- Linux权限机制
权限是操作系统用来限制用户.组.进程对操作系统资源(文件.设备等)的访问的机制 权限分为:读.写.执行,一般表示为 r.w.x http://itercast.com/lecture/22 每个文件或 ...
- 线程篇-01-NSThread
一.概述 1.使用NSThread创建线程的三种方式和区别. 二.核心 2.1 NSThread创建线程的三种方式和区别. 主要有NSThread对象的创建线程的类方法detachNewThreadS ...
- Java I/O 模型的演进
什么是同步?什么是异步?阻塞和非阻塞又有什么区别?本文先从 Unix 的 I/O 模型讲起,介绍了5种常见的 I/O 模型.而后再引出 Java 的 I/O 模型的演进过程,并用实例说明如何选择合适的 ...
- Hive 11、Hive嵌入Python
Hive嵌入Python Python的输入输出都是\t为分隔符,否则会出错,python脚本输入print出规定格式的数据 用法为先add file,使用语法为TRANSFORM (name, it ...
- Python多线程(threading模块)
线程(thread)是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不同的任务. ...
- GCD 延时操作
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_ ...
- mysql 自己定义存储过程和触发器
mysql 自己定义存储过程和触发器 --存储过程示范 DROP PROCEDURE IF EXISTS PRO_TEST; CREATE PROCEDURE PRO_TEST(IN NUM_IN I ...
- HashMap的使用方法及注意事项
99.Map(映射):Map 的keySet()方法会返回 key 的集合,因为 Map 的键是不能重复的,因此 keySet()方法的返回类型是 Set:而 Map 的值是可以重复的,因此 valu ...