poj 1995 Raising Modulo Numbers 题解
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 6347 | Accepted: 3740 |
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
input consists of Z assignments. The number of them is given by the
single positive integer Z appearing on the first line of input. Then the
assignements follow. Each assignement begins with line containing an
integer M (1 <= M <= 45000). The sum will be 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
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#define maxn 50001
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x7fffffff
#define p 23333333333333333
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int m,h;
long long ans;
long long kuaisumi(long long a,long long n)
{
long long ans=;
while(n) {
if(n&) ans=(ans*a)%m;
a=(a*a)%m;
n>>=;
}
return ans;
}
int main()
{
int t;
cin>>t;
while(t--){
ans=;
cin>>m>>h;
for(int i=;i<h;i++)
{
long long a,b;
cin>>a>>b;
ans=(ans+kuaisumi(a,b))%m;
}
cout<<ans<<endl;
}
return ;
}
poj 1995 Raising Modulo Numbers 题解的更多相关文章
- poj 1995 Raising Modulo Numbers【快速幂】
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5477 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 ...
- POJ 1995 Raising Modulo Numbers (快速幂)
题意: 思路: 对于每个幂次方,将幂指数的二进制形式表示,从右到左移位,每次底数自乘,循环内每步取模. #include <cstdio> typedef long long LL; LL ...
- 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 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: ...
随机推荐
- C语言小程序之整除
看到有人要求用C语言写这样一个小程序,就拿来温习一下 需求:输出从1到2015这2015个自然数中,能被4或5整除,但不能被30整除的数,并计算有多少个数. #include<stdio.h ...
- 【Java】数组的打印输出
import java.util.Arrays; public class Test { public static void main(String[] args) { int[] a = { 1, ...
- ref:Adding AFL Bloom Filter to Domato for Fun
ref:https://www.sigpwn.io/blog/2018/5/13/adding-afl-bloom-filter-to-domato-for-fun Adding AFL Bloom ...
- 路径方案数 [SPFA,拓扑排序]
路径方案数 [题目描述] 给一张无向图,n 个点和 m 条边,cyb 在 1 号点,他要去 2 号点, cyb 可以从 a 走到 b,当且仅当 a 到 2 的最短路,比 b 到 2 的最短路长. 求 ...
- Android Service AIDL
http://blog.csdn.net/liuhe688/article/details/6400385 在Android中,如果我们需要在不同进程间实现通信,就需要用到AIDL技术去完成. AID ...
- arm Linux 驱动LED子系统 测试
Linux内核在3.0以上引入了设备树概念(具体哪个版本不清楚)在编译内核后需要将与之对应的dtb文件也下载人板子上才能使内核与硬件关联起来. dtb文件是有dts文件编译后生成的:例如 /* * C ...
- 应用程序首选项(application preference)及数据存储
应用程序首选项(application preference)用来存储用户设置,考虑以下案例: a. 假设有一款MP3播放器程序,当用户调节了音量,当下次运行该程序时,可能希望保持上一次调节的音量值. ...
- luoguP4457 [BJOI2018]治疗之雨 概率期望 + 高斯消元
应该是最后一道紫色的概率了....然而颜色啥也代表不了.... 首先看懂题意: 你现在有$p$点体力,你的体力上限为$n$ 在一轮中, 1.如果你的体力没有满,你有$\frac{1}{m + 1}$的 ...
- luoguP4115 QTREE4 链分治
具体看$qzc$论文吧......陈年老物了...... 主要注意每个链头一棵线段树而不是一棵全局线段树 修改操作写完就是正确的,反而是初始化调了好一会...... 跑的还是很快的,有些地方没优化常数 ...
- 字符约束条件的SQL注入攻击
引言 目前值得高兴的是,开发者在建立网站时,已经开始关注安全问题了——几乎每个开发者都知道SQL注入漏洞了.在本文中,我将为读者介绍另一种与SQL数据库相关的漏洞,虽然它的危害性与SQL注入不相上下, ...