poj_1995_Raising Modulo Numbers
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
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
ai^bi mod m
快速幂裸题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
typedef long long LL;
#include<algorithm>
using namespace std;
LL pow(LL a,LL n,LL mod)
{
LL base=a,ret=1;
while(n)
{
if(n&1) ret=(ret*base)%mod;
base=(base*base)%mod;
n>>=1;
}
return ret%mod;
}
int main()
{
LL m,t,h;
scanf("%lld",&t);
while(t--)
{
cin>>m;
// cout<<"m="<<m<<endl;
cin>>h;
LL ans=0;
for(LL i=0;i<h;i++)
{
LL a,b;
scanf("%lld%lld",&a,&b);
ans=(ans+pow(a,b,m))%m;
}
cout<<ans%m<<endl;
}
}
poj_1995_Raising Modulo Numbers的更多相关文章
- 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: 5477 Accepted: ...
- POJ1995 Raising Modulo Numbers(快速幂)
POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...
- 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 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6347 Accepted: ...
- POJ:1995-Raising Modulo Numbers(快速幂)
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9512 Accepted: 578 ...
- poj1995 Raising Modulo Numbers【高速幂】
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5500 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: ...
随机推荐
- Java中的内存泄漏分析说明
Java语言的一个关键的优势就是它的内存管理机制.你只管创建对象,Java的垃圾回收器帮你分配以及回收内存.然而,实际的情况并没有那么简单,因为内存泄漏在Java应用程序中还是时有发生的. 下面就解释 ...
- JEECMS站群管理系统-- 首页的加载过程
在浏览器中输入http://localhost:8080/jeecms,回车 首先进入配置文件web.xml, <context-param> <param-name>cont ...
- GitKraken使用教程-基础部分(7)
8. 本地分支和标签 1) 在提交记录区中查看分支状态 提交记录区中每一个分支都位于一个提交记录所在的行中. 从图 2‑1中可以看到,服务器上的master分支停留在整理格式(把这个提交记录记为or ...
- checkbox判断选中的三种方法
方法一: if ($("#checkbox-id")get(0).checked) { // do something } 方法二: if($('#checkbox-id' ...
- Redis-Service.Stack的初级使用
主要解决Redis服务器带有密码的情况下初始化. 创建RedisHelper类,直接贴代码: using ServiceStack.Redis;using System;class RedisHelp ...
- 延迟查询--LINQ
1.LINQ查询使用的是延迟查询的方法,以便提高效率 public static IEnumerable<TSource> Where<TSource>(this IEnume ...
- spring-cloud构架微服务(2)-全局配置二
接上篇,实际项目中,可能会遇到有些配置项,例如:邮件地址.手机号等在服务已经上线之后做了改动(就当会出现这种情况好了).然后你修改了配置信息,就得一个一个去重启对应的服务.spring-全局配置提供了 ...
- intel Skylake平台安装WIN7
目前针对IntelSkylake平台安装WIN7时USB接口失灵的问题,不少硬件厂商都推出了免费修改工具来集成XHCI USB控制器驱动,这其中技嘉提供了一款Windows USB Installat ...
- 2017.10.28 QB模拟赛 —— 上午
题目链接 T1 1e18 内的立方数有 1e6个 直接枚举可过 二分最优 考场用set 死慢.. #include <cstdio> int t; long long p; int ma ...
- ubuntu 显示隐藏文件
原文链接 http://blog.csdn.net/happyjiahan/article/details/6023496 方法1.使用命令ls -a显示所有的文件,包括隐藏文件 方法2.在桌面化操作 ...