博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1995 快速幂(裸)
阅读量:7122 次
发布时间:2019-06-28

本文共 2384 字,大约阅读时间需要 7 分钟。

Raising Modulo Numbers
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 9218   Accepted: 5611

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 Ai
Bi 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

31642 33 44 55 63612312374859 30293821713 18132

Sample Output

21319513 直接裸快速幂就能过了
#include
using namespace std;int pow1(int a,int b,int m){ int res = 1; a %= m; while(b) { if(b&1) res = res*a%m; a = a*a%m; b >>= 1; } return res;}int main(){ int n; int mod,m,sum; int a,b; cin>>n; while(n--) { cin>>mod>>m; sum = 0; for(int i = 0;i
>a>>b; sum = (sum + pow1(a,b,mod))%mod; } cout<
<

 

转载于:https://www.cnblogs.com/ZZUGPY/p/8479607.html

你可能感兴趣的文章
测试用例编写规范
查看>>
SWIFT系统第三家银行曝遭网络劫匪抢走1200万美元
查看>>
Java的GC机制
查看>>
espresso系列3--测试实践
查看>>
espresso基础架构与API分析
查看>>
《Python语言程序设计》——2.15 本章总结
查看>>
《音乐达人秀:Adobe Audition CC实战222例》——实例5 麦克风说话和音乐播放等所有声音都混合录制...
查看>>
TIOBE 9 月编程语言排行榜,新 TIOBE 指数算法
查看>>
《Adobe Photoshop CC经典教程》—第2课2.6节使用Spot Healing Brush工具
查看>>
《AngularJS实战》——2.3 Angular中的模板
查看>>
《Node.js区块链开发》——2.5 风险提示
查看>>
《ANSYS 14热力学/电磁学/耦合场分析自学手册》——2.9 图形窗口
查看>>
阿里 MySQL 团队加入参与 WebScaleSQL 开发
查看>>
《Adobe After Effects CC经典教程》——2.3 创建新合成图像
查看>>
提高 PHP 代码质量的 36 计
查看>>
《Adobe Premiere Pro CS4经典教程》——1.4 提供标准的数字视频工作流
查看>>
《CCNP TSHOOT 300-135学习指南》——1.4节本章小结
查看>>
诺基亚将更名为微软移动
查看>>
Vue.js 作者尤雨溪加盟 Weex 团队担任技术顾问
查看>>
js初级脚本算法
查看>>