poj1995 Raising Modulo Numbers【高速幂】
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 5500 | Accepted: 3185 |
Description
was so far underestimated and that there is lack of such games. This kind of game was thus included into the KOKODáKH. The rules follow:
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
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
#include<stdio.h>
#include<string.h>
int ksm(long long a,long long b,long long n)
{
long long ans=1;
while(b)
{
if(b&1)
ans=ans*a%n;
//写成ans*=a%n不行...输出错误
a=a*a%n;
b>>=1;
}
return ans;
}
int main()
{
int z,h,m,u,i;
scanf("%d",&z);
while(z--)
{
int sum = 0;
scanf("%d",&m);
scanf("%d",&h);
while(h--)
{
scanf("%d%d",&u,&i);
sum += ksm(u,i,m);
sum %= m;
}
printf("%d\n",sum);
}
return 0;
} /*************************************************************/ #include<stdio.h>
#include<string.h>
int main()
{
long long z,h,m,a,b,ans;
scanf("%lld",&z);
while(z--)
{
int sum = 0;
scanf("%lld",&m);
scanf("%lld",&h);
while(h--)
{
scanf("%lld%lld",&a,&b);
ans = 1;
while(b)
{
if(b&1)
ans=ans*a%m;
a=a*a%m;
b>>=1;
}
sum += ans;
sum %= m;
}
printf("%d\n",sum%m);
}
return 0;
}
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(快速幂取余)
题目:http://poj.org/problem?id=1995 题目解析:求(A1B1+A2B2+ ... +AHBH)mod M. 大水题. #include <iostream> ...
- 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: 5532 Accepted: ...
- ZOJ2150 Raising Modulo Numbers 快速幂
ZOJ2150 快速幂,但是用递归式的好像会栈溢出. #include<cstdio> #include<cstdlib> #include<iostream> # ...
- POJ-1995 Raising Modulo Numbers---快速幂模板
题目链接: https://vjudge.net/problem/POJ-1995 题目大意: 求一堆ab的和模上m 思路: 直接上模板 #include<iostream> #inclu ...
- POJ 1995 Raising Modulo Numbers (快速幂)
题意: 思路: 对于每个幂次方,将幂指数的二进制形式表示,从右到左移位,每次底数自乘,循环内每步取模. #include <cstdio> typedef long long LL; LL ...
- 【POJ - 1995】Raising Modulo Numbers(快速幂)
-->Raising Modulo Numbers Descriptions: 题目一大堆,真没什么用,大致题意 Z M H A1 B1 A2 B2 A3 B3 ......... AH ...
- Raising Modulo Numbers(POJ 1995 快速幂)
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5934 Accepted: ...
随机推荐
- Nginx详细编译参数
本参数基于Nginx-1.15.2安装包 一 路径参数 1.1.1 指定Nginx安装路径 --prefix=/usr/local/nginx- 1.1.2 设置Nginx可执行文件路径默认路径在 - ...
- 【例题 6-20 UVA - 1599】Ideal Path
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 逆向做一遍bfs. 得到终点到某个点的最短距离. 这样,我们从起点顺序的时候. 就能知道最短路的下一步是要走哪里了. 这样,我们从起 ...
- TPS54232-------电源管理芯片
TPS54232 DC DC开关稳压器 电源管理芯片 放大器俗称功放 注意看芯片的次序1~8是如何排布的,这个规律一般是固定的 也许我们整理多了就能发现引脚的宽度和长度都是规格好的. 下面是封装: 所 ...
- echarts3.0 仪表盘实例更改完成占用率实例
需要完成的项目效果 官方实例效果 基本思路: 首先引入jquery和echarts3.0库. 需要两个仪表盘,一个仪表盘是纯色灰色,在底部.startAngle 和endAngle永远是最大值,默认为 ...
- UVA 11800 - Determine the Shape 几何
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 【CS Round #48 (Div. 2 only)】Water Volume
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举0在哪个位置就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> us ...
- 年轻By塞缪尔·厄尔曼
年轻,并非人生旅程的一段时光,也并非粉颊红唇和体魄的矫健. 它是心灵中的一种状态,是头脑中的一个意念,是理性思维中的创造潜力,是情感活动中的一股勃勃的朝气,是人生春色深处的一缕东风. 年轻,意味着甘愿 ...
- Intel X86 CPU 系列的寻址方式
Intel X86 CPU 系列的寻址方式 数据总线和地址总线要尽量相同,这个是一个地址就是一个指针.
- 4、runtime电源管理模式(内核文档runtime_pm.txt有详细描述)
系统睡眠模型是让整个系统休眠,而runtime是在系统正常工作的时候单独控制某个设备休眠和唤醒 1. runtime PM流程怎样动态地打开或关闭设备的电源?最简单的方法:在驱动程序里,在open函数 ...
- AE开发技术文档--8种数据访问方法
转自原文 AE开发技术文档--8种数据访问方法 1.shapefile IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new Sha ...