poj 1995 Raising Modulo Numbers【快速幂】
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 5477 | Accepted: 3173 |
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
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#define DD double
#define LL long long
#define INF 0x3f3f3f
#define MAX 1010
using namespace std;
int fun(int a,int b,int c)
{
int ans=1;
a=a%c;
while(b)
{
if(b&1)
ans=(a*ans)%c;
b=b/2;
a=(a*a)%c;
}
return ans;
}
int main()
{
int t,i,j;
int n,m,sum;
int x,y;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
sum=0;
for(i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
sum=fun(x,y,m)+sum;
}
printf("%d\n",sum%m);
}
return 0;
}
poj 1995 Raising Modulo Numbers【快速幂】的更多相关文章
- POJ 1995 Raising Modulo Numbers (快速幂)
题意: 思路: 对于每个幂次方,将幂指数的二进制形式表示,从右到左移位,每次底数自乘,循环内每步取模. #include <cstdio> typedef long long LL; LL ...
- POJ 1995:Raising Modulo Numbers 快速幂
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5532 Accepted: ...
- POJ1995 Raising Modulo Numbers(快速幂)
POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...
- poj 1995 Raising Modulo Numbers 题解
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6347 Accepted: ...
- POJ 1995 Raising Modulo Numbers 【快速幂取模】
题目链接:http://poj.org/problem?id=1995 解题思路:用整数快速幂算法算出每一个 Ai^Bi,然后依次相加取模即可. #include<stdio.h> lon ...
- POJ 1995 Raising Modulo Numbers(快速幂)
嗯... 题目链接:http://poj.org/problem?id=1995 快速幂模板... AC代码: #include<cstdio> #include<iostream& ...
- POJ 1995 Raising Modulo Numbers
快速幂取模 #include<cstdio> int mod_exp(int a, int b, int c) { int res, t; res = % c; t = a % c; wh ...
- ZOJ2150 Raising Modulo Numbers 快速幂
ZOJ2150 快速幂,但是用递归式的好像会栈溢出. #include<cstdio> #include<cstdlib> #include<iostream> # ...
- POJ1995:Raising Modulo Numbers(快速幂取余)
题目:http://poj.org/problem?id=1995 题目解析:求(A1B1+A2B2+ ... +AHBH)mod M. 大水题. #include <iostream> ...
随机推荐
- SQL Trigger(触发器)
1.触发器对表进行插入.更新.删除的时候会自动执行的特殊存储过程. 2.触发器一般用在check约束更加复杂的约束上面. 3.触发器和普通的存储过程的区别是:触发器是当对某一个表进行操作. 4.upd ...
- ODBC方式连接Informix数据库
公司某个报表系统使用Informix数据库,在谋划使用Perl语言写数据采集程序后,花费了很多时间建立Perl访问Informix连接.恰巧Windows下ActivePerl的CPAN中又没有DBD ...
- ubuntu远程登陆windows
首先安装rdesktop : apt-get install rdesktop.p 程序安装完后,在终端命令行中输入:$ rdesktop -g 1024x768 -d 24 ip,就进入了windo ...
- Python学习_数据处理split方法
用open方法导入文件“sketch.txt”后,用split()方法进行分割: >>> import os >>> os.chdir('C:/Python33/H ...
- E8.ITSM IT运维服务管理系统
一. IT运维面临问题 随着企业信息化项目若干年以来的建设积累,IT资产日趋庞大,以及内外部监管部门对IT运维的要求也越来越严格规范,业务部门对企业的IT运维管理也提出了更高的要求. IT ...
- HTML5+CSS3鼠标悬停图片特效
点击预览效果 下载该特效: HTML5+CSS3鼠标悬停图片特效.zip 特效说明: 一款HTML5+CSS3鼠标悬停图片事件网页特效,集合了最流行鼠标悬停图片文字.图片动画移动 ...
- A simple test
博士生课程报告 视觉信息检索技术 博 士 生:施 智 平 指导老师:史忠植 研究员 中国科学院计算技术研究所 2005年1月 目 ...
- WinterCamp 2015 总结
这次WC2015确实有很多遗憾,特别是考试的时候犯的低级错误,由于我没有看到第三题每个点输出不全可以得小分,对于又没跑出来的点,我都根本没有上交.这确实是一个很悲伤的事情,但是也给我了足够时间去反思. ...
- forward:hello 与 redirect:hello的区别
对于某些Controller的处理方法,当返回值为String类型时,返回的结果中可能含有forward或redirect前缀: 如: @Controller @RequestMapping(&quo ...
- ANDROID_MARS学习笔记_S02_012_ANIMATION_利用AnimationListener在动画结束时删除或添加组件
一.代码 1.xml(1)activity_main.xml <?xml version="1.0" encoding="utf-8"?> < ...