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: ...
随机推荐
- iOS控制器与视图加载方法
转载记录, 请看原文: 1. iOS中的各种加载方法(initWithNibName,loadNibNamed,initWithCoder,awakeFromNib等等)简单使用 http://w ...
- 环状序列(UVa1584)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...
- day6 random随机数模块
random 我们经常看到网站的随机验证码,这些都是由随机数生成的,因此我们需要了解一下随机数的模块.如何生成随机数. random 生成随机数 random.random() 生成0- ...
- 当参数为带参数的url时怎么办?
比如地址为:http://www.baidu.com/index.aspx?url=http://www.baidu.com/info.aspx?id=1&type=1,用Request[&q ...
- 【LOJ】#2172. 「FJOI2016」所有公共子序列问题
题解 听说是什么序列自动机? 我们考虑对于每个位置的串,下面拼接相同的字符时,拼接最近的一个,这样可以保证不重不漏 为了实现这个我们需要什么呢,我们需要一个链表,记录一下每个位置的下一个字符会转移到哪 ...
- Ubuntu 18.04 更改静态IP
2018年4月26日,ubuntu 18.04发行,第一时间下载安装了SERVER版本.使用VM14版本的虚拟机,开始使用DHCP获得IP地址,没有意外,可以直接上网.然而在更改VM的网络模式为桥接模 ...
- vue开发关于微信授权登录以及路由mode模式(Hash|History)和手机平台(andriod|IOS)不得不说的故事
引用链接: https://segmentfault.com/a/1190000010753247?utm_source=tuicool&utm_medium=referral
- linux——(5)文件与文件系统的压缩与打包
概念一:常见的压缩文件拓展名 .z compress程序压缩的文件. .gz gzip程序压缩的文件. .bz2 bzip2程序压缩的文件. .tar tar程序打包的数据,并没有压缩过. .tar. ...
- 阿里云提示Discuz memcache+ssrf GETSHELL漏洞如何解决
一般这个漏洞都是下面文件,source/function/function_core.php 搜索下面代码: $content = preg_replace($_G['setting']['outpu ...
- QT学习笔记2:QT中常用函数
一.QString转number QString number() QString number() QString number() QString number() QString number( ...