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 ...
随机推荐
- Android使用的Eclipse NDK开发较详细一篇文章
转自: http://www.cnblogs.com/zdz8207/archive/2012/11/27/android-ndk-install.html
- *.location.href 用法:
*.location.href 用法: top.location.href=”url” 在顶层页面打开url(跳出框架) self.location.href=”url” ...
- MVC4 开篇
开篇,肯定不讲技术. 新项目开工了,用到了MVC4,赶快来园子吐槽下. 刚出来一年,学到了一些东西,但是自知比菜鸟还不如,空闲不看书,不练习demo,快吐我吧... 哈哈,吐吧,哥还是一样淡定,淡定, ...
- acl拒绝访问流量
interface Ethernet0/0 ip address 12.1.1.2 255.255.255.0 ip access-group 10 in half-duplex R1# ...
- Linux 进程通信(共享内存区)
共享内存是由内核出于在多个进程间交换信息的目的而留出的一块内存区(段). 如果段的权限设置恰当,每个要访问该段内存的进程都可以把它映像到自己的私有地址空间中. 如果一个进程更新了段中的数据,其他进程也 ...
- AE笔记
我想做一个好玩的视频,需要用到AE,写点东西锻炼语言能力,视频教程后续录制到时放链接. 一.合成 拖进项目的视频要新建合成才能加以编辑,新建合成很简单,拖拽你的视频向下到一个类似相片的图标上面就新建成 ...
- 关联规则算法(The Apriori algorithm)详解
一.前言 在学习The Apriori algorithm算法时,参考了多篇博客和一篇论文,尽管这些都是很优秀的文章,但是并没有一篇文章详解了算法的整个流程,故整理多篇文章,并加入自己的一些注解,有了 ...
- 浩瀚先森(guohao1206.com)
博客搬家啦,新博客地址:浩瀚先森 http://www.guohao1206.com
- 一个基于.NET平台的自动化/压力测试系统设计简述
AutoTest系统设计概述 AutoTest是一个基于.NET平台实现的自动化/压力测试的系统,可独立运行于windows平台下,支持分布式部署,不需要其他配置或编译器的支持.(本质是一个基于协议的 ...
- Bootstrap系列 -- 24. 下拉菜单基本用法
在使用Bootstrap框架的下拉菜单时,必须调用Bootstrap框架提供的bootstrap.js文件.当然,如果你使用的是未编译版本,在js文件夹下你能找到一个名为“dropdown.js”的文 ...