UVA 10692 Huge Mod
Problem X
Huge Mod
Input: standard input
Output: standard output
Time Limit: 1 second
The operator for exponentiation is different from the addition, subtraction, multiplication or division operators in the sense that the default associativity for exponentiation goes right to left instead of left to right. So unless we mess it up by placing parenthesis,
should mean
not
. This leads to the obvious fact that if we take the levels of exponents higher (i.e., 2^3^4^5^3), the numbers can become quite big. But let's not make life miserable. We being the good guys would force the ultimate value to be no more than 10000.
you only need to compute a1^a2^a3^...^aN mod m.
Input
There can be multiple (not more than 100) test cases. Each test case will be presented in a single line. The first line of each test case would contain the value for M(2<=M<=10000). The next number of that line would be N(1<=N<=10). Then N numbers - the values for a1, a2, a3, ... , aN would follow. You can safely assume that 1<=ai<=1000. The end of input is marked by a line containing a single hash ('#') mark.
Output
For each of the test cases, print the test case number followed by the value of a1^a2^a3^...^aN mod m on one line. The sample output shows the exact format for printing the test case number.
Sample Input |
Sample Output |
10 4 2 3 4 5 100 2 5 2 53 3 2 3 2 # |
Case #1: 2 Case #2: 25 Case #3: 35 |
题意:求出 a0^a1^a2......a^n%m的值。
sl: 以前做过一个a^B mod 1e9+7 的题,那个很显然是费马小定理。碰见这个题目傻逼了。
百度学习一翻知:A^x=A^(x%phi[[m]+phi[m]) (phi[m]<=x) 很显然一个递归的式子。
哎,但是当时每次都是对x%phi[MOD] 傻叉了。应该递归求解。
坑了我4个点真吭。。。
UVA 10692 Huge Mod的更多相关文章
- uva 10692 - Huge Mods(数论)
题目链接:uva 10692 - Huge Mods 题目大意:给出一个数的次方形式,就它模掉M的值. 解题思路:依据剩余系的性质,最后一定是行成周期的,所以就有ab=abmod(phi[M])+ph ...
- uva 10692 Huge Mods 超大数取模
vjudge上题目链接:Huge Mods 附上截图: 题意不难理解,因为指数的范围太大,所以我就想是不是需要用求幂大法: AB % C = AB % phi(C) + phi(C) % C ( B ...
- UVA 10692 Huge Mods(指数循环节)
指数循环节,由于a ^x = a ^(x % m + phi(m)) (mod m)仅在x >= phi(m)时成立,故应注意要判断 //by:Gavin http://www.cnblogs. ...
- uva 10692 高次幂取模
Huge Mod Input: standard input Output: standard output Time Limit: 1 second The operator for exponen ...
- Huge Mods UVA - 10692(指数循环节)
题意: 输入正整数a1,a2,a3..an和模m,求a1^a2^...^an mod m 解析: #include <iostream> #include <cstdio> # ...
- 【题解】Huge Mods UVa 10692 欧拉定理
题意:计算a1^( a2^( a3^( a4^( a5^(...) ) ) ) ) % m的值,输入a数组和m,不保证m是质数,不保证互质 裸的欧拉定理题目,考的就一个公式 a^b = a^( b % ...
- UVa 374 - Big Mod
题目大意:计算R = BP mod M,根据模运算的性质计算. 正常计算会超时,可以用分治的思想降低时间复杂度.不过如果遇到00,结果...话说00的结果是1吗?忘了都... #include < ...
- acm数论之旅--欧拉函数的证明
随笔 - 20 文章 - 0 评论 - 73 ACM数论之旅7---欧拉函数的证明及代码实现(我会证明都是骗人的╮( ̄▽ ̄)╭) https://blog.csdn.net/chen_ze_hua ...
- 一位学长的ACM总结(感触颇深)
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...
随机推荐
- Akka源码分析-Cluster-ClusterClient
ClusterClient可以与某个集群通信,而本身节点不必是集群的一部分.它只需要知道一个或多个节点的位置作为联系节点.它会跟ClusterReceptionist 建立连接,来跟集群中的特定节点发 ...
- 【杂文】虚拟键码表(供函数GetAsyncKeyState()使用)
[杂文]虚拟键码表(供函数GetAsyncKeyState()使用) 什么?你说你不知道 \(GetAsyncKeyState()\) ?\(→\)戳我\(←\) (惊奇的发现 \(0\) ~ \(9 ...
- [C陷阱和缺陷] 第3章 语义“陷阱”
第3章 语义"陷阱" 一个句子哪怕其中的每个单词都拼写正确,而且语法也无懈可击,仍然可能有歧义或者并非书写者希望表达的意思.程序也有可能表面上是一个意思,而实际上的意思却相 ...
- [TYVJ1391]走廊泼水节
Description 话说,中中带领的OIER们打算举行一次冬季泼水节,当然这是要秘密进行的,绝对不可以让中中知道.不过中中可是老江湖了,当然很快就发现了我们的小阴谋,于是他准备好水枪迫不及待的想要 ...
- [转]MVC4项目中验证用户登录一个特性就搞定
本文转自:http://www.mrhuo.com/Article/Details/470/A-Attribute-For-MVC4-Project-Used-To-Validate-User-Log ...
- SQL server中的T-SQL语句
首先点击新建查询 如下图所示 创建数据库:create database 数据库名称 使用数据库:use 数据库名称 创建表:create table 表名 ( 代码 ) 输入完成执行时需选中 如果需 ...
- python之路 之一pyspark
pip包下载安装pyspark pip install pyspark 这里可能会遇到安装超时的情况 加参数 --timeout=100 pip -default -timeout=1 ...
- NX自动出图
小秀一下战果: 1. 自动添加图框2. 自动添加投影视图3. 自动标注外形尺寸4. 根据工艺要求,自动添加公差5. 自动孔表6. 批量打印 欢迎大家积极吐槽哈 [视频演示] http://v.youk ...
- vuex理解之modules小记
好记性不如烂笔头 demo预览 源代码 前情提要 关于vuex,其实很久以前就研究使用过,还研究过 flux,redux之类的体系,当时感觉对于 state,action,dispatch,views ...
- Vue指令7:v-model
可以用 v-model 指令在表单控件元素上创建双向数据绑定. v-model 会忽略所有表单元素的 value.checked.selected 特性的初始值. 因为它会选择 Vue 实例数据来作为 ...