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

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.

上面的可以不用看。算output里面的那个式子就行。
 

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

快速幂裸题,暴力算的话会TLE。

 //快速幂
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int Z,M;
int n;
int sum;
int a,b;
int ksm(int a,int b){
int now=a%M;
int res=;
while(b){
if(b&)res=res*now%M;
now=now*now%M;
b>>=;
}
return res;
}
int main(){
scanf("%d",&Z);
while(Z--){
sum=;
scanf("%d",&M);
scanf("%d",&n);
int i,j;
for(i=;i<=n;i++){
scanf("%d%d",&a,&b);
sum=(sum+ksm(a,b))%M;//累加
}
printf("%d\n",sum);
}
return ;
}

POJ1995 Raising Modulo Numbers的更多相关文章

  1. POJ1995 Raising Modulo Numbers(快速幂)

    POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...

  2. poj1995 Raising Modulo Numbers【高速幂】

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

  3. POJ1995:Raising Modulo Numbers(快速幂取余)

    题目:http://poj.org/problem?id=1995 题目解析:求(A1B1+A2B2+ ... +AHBH)mod M. 大水题. #include <iostream> ...

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

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

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

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

  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 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6347   Accepted: ...

  8. POJ 1995:Raising Modulo Numbers 快速幂

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

  9. POJ1995:Raising Modulo Numbers

    二进制前置技能:https://www.cnblogs.com/AKMer/p/9698694.html 题目传送门:http://poj.org/problem?id=1995 题目就是求\(\su ...

随机推荐

  1. Java基础详解 (一)Java的类成员访问权限修饰词(以及类访问权限)

    在一个类的内部,其成员(包括成员变量和成员函数)能否被其他类所访问,取决于该成员的修饰词.Java的类成员访问权限修饰词有四类:private,无(默认情况下),protected和public.其权 ...

  2. Windows Server 2008 DNS服务器安装与配置

    Windows Server 2008 DNS服务器安装与配置本文关键字:Windows Server 2008 DNS.IIS 服务器安装与配置,DNS服务器本文来源:http://www.ip-t ...

  3. ajax载入数据是小细节

    今天看了一个点子: 在 ajax 导入数据的 div中添加一些样式,比如:我们正紧急抢救 增加趣味性,有解决数据卡壳问题

  4. Css 特殊或不常用属性

    1. -webkit-font-smoothing: antialiased; CSS3中用于webkit引擎(如chrome)中设置字体的抗锯齿或者说光滑度的属性.有3个属性:none用于小像素的文 ...

  5. sql 索引 填充因子(转)

    和索引重建最相关的是填充因子.当创建一个新索引,或重建一个存在的索引时,你可以指定一个填充因子,它是在索引创建时索引里的数据页被填充的数量.填充因子设置为100意味着每个索引页100%填满,50%意味 ...

  6. performSelector:withObject:afterDelay: 精要概览(持续更新)

    - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay; - ...

  7. Linux Linux程序练习十(网络编程大文件发送)

    //网络编程客户端--大文件传输 #include <stdio.h> #include <stdlib.h> #include <string.h> #inclu ...

  8. 通过spring,在项目的任意位置获取当前Request

    需要引入: import javax.servlet.http.HttpServletRequest; import org.springframework.web.context.request.R ...

  9. caffe windows 学习第一步:编译和安装(vs2012+win 64)

    没有GPU,没有linux, 只好装caffe的windows版本了. 我的系统是win10(64位),vs 2012版本,其它什么都没有装,因此会需要一切的依赖库. 其实操作系统只要是64位就行了, ...

  10. 从0开始学java——JUnit4 复习,其实基本思想还是那些,不过采用了新的注释格式的语法

    看了深入探索 JUnit 4(http://www.ibm.com/developerworks/cn/education/java/j-junit4/index.html  ) 主要是讲了新的基于注 ...