Raising Modulo Numbers
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 6347   Accepted: 3740

Description

People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that this market segment 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

The
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

For each assingnement there is the only one line of output. On this line, there is a number, the result of expression

(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 题解的更多相关文章

  1. poj 1995 Raising Modulo Numbers【快速幂】

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5477   Accepted: ...

  2. POJ 1995 Raising Modulo Numbers 【快速幂取模】

    题目链接:http://poj.org/problem?id=1995 解题思路:用整数快速幂算法算出每一个 Ai^Bi,然后依次相加取模即可. #include<stdio.h> lon ...

  3. POJ 1995 Raising Modulo Numbers(快速幂)

    嗯... 题目链接:http://poj.org/problem?id=1995 快速幂模板... AC代码: #include<cstdio> #include<iostream& ...

  4. 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 ...

  5. POJ 1995 Raising Modulo Numbers (快速幂)

    题意: 思路: 对于每个幂次方,将幂指数的二进制形式表示,从右到左移位,每次底数自乘,循环内每步取模. #include <cstdio> typedef long long LL; LL ...

  6. Raising Modulo Numbers(POJ 1995 快速幂)

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5934   Accepted: ...

  7. 【POJ - 1995】Raising Modulo Numbers(快速幂)

    -->Raising Modulo Numbers Descriptions: 题目一大堆,真没什么用,大致题意 Z M H A1  B1 A2  B2 A3  B3 ......... AH  ...

  8. POJ 1995:Raising Modulo Numbers 快速幂

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5532   Accepted: ...

  9. POJ1995 Raising Modulo Numbers

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6373   Accepted: ...

随机推荐

  1. 微信小程序之wepy自动化架构搭建(fly+wepy-plugin-replace)

    前言 本文章秉着自动化工程项目的思想搭建的,基础架子完全按照wepy官网搭建,在基础上增加配置达到自动化项目.新增动flxio拦截器自动处理接口,新增根据环境变量来改变运行时的参数. Fly.js 小 ...

  2. 解决xshell4中文乱码

    前言 在公司看到别人使用xshell后,由于之前一直使用SecureCRT所以心里一直痒痒的想换下xshell试下.于是在昨天晚上使用xshell,却被中文乱码折腾了很长时间以至于想放弃,最终灵光一现 ...

  3. String 不变性以及 Java 值传递和引用传递

    String 不变性以及 Java 值传递和引用传递 public class Example { String str = new String("good"); char[] ...

  4. 一个完整的 JS 身份证校验代码

    一个完整的 JS 身份证校验代码 身份证号码是由 18 位数字组成的,它们分别表示: (1) 前 1.2 位数字表示: 所在省份的代码; (2) 第 3.4 位数字表示: 所在城市的代码; (3) 第 ...

  5. Unity 游戏开发技巧集锦之材质的应用的创建反射材质

    Unity 游戏开发技巧集锦之材质的应用的创建反射材质 Unity中材质的应用 游戏中,大多数材质的应用都离不开纹理,而纹理本身是图片.所以,在学习本章时,最好在电脑上安装一个可以编辑图片的功能强大的 ...

  6. redis_NoSql入门概述

    一.为什么要使用Nosql 今天我们可以通过第三方平台(如:google,facebook)可以很容易的访问和抓取数据.用户的个人信息,社交网络,地理位置,用户生成的数据和用户操作日志已经成倍的增加. ...

  7. [BZOJ3583]杰杰的女性朋友(矩阵快速幂)

    杰杰的女性朋友 时间限制:10s      空间限制:256MB 题目描述 杰杰是魔法界的一名传奇人物.他对魔法具有深刻的洞察力,惊人的领悟力,以及令人叹为观止的创造力.自从他从事魔法竞赛以来,短短几 ...

  8. [BZOJ4196][NOI2015]软件包管理器(树链剖分)

    4196: [Noi2015]软件包管理器 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 2166  Solved: 1253[Submit][Sta ...

  9. bzoj4753 最佳团体

    题目描述 JSOI 信息学代表队一共有 NN 名候选人,这些候选人从 11 到 NN 编号.方便起见,JYY 的编号是 00 号.每个候选人都由一位编号比他小的候选人R_iRi​ 推荐.如果 R_i ...

  10. php 导出excel

    <?phpclass Excel { var $inEncode; var $outEncode; public function _construct() { } public functio ...