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 ...
随机推荐
- 为什么JavaWeb项目要分层
首先让我们坐着时光机回到n年前的web开发.那个时候最早都是静态的html页面,后来有了数据库,有了所谓的动态页面,然后程序猿在编码的时候,会把所有的代码都写在页面上,包括数据库连接,包括事务控制,接 ...
- git clone ssh permissions are too open 解决方案。
错误如图所示 方案如下 https://stackoverflow.com/questions/9270734/ssh-permissions-are-too-open-error
- 用Movie显示gif(1)SimpleGif
代码如下: import android.content.Context; import android.graphics.Canvas; import android.graphics.Movie; ...
- [译]curl_multi_info_read
curl_multi_info_read - read multi stack informationals读取multi stack中的信息 SYNOPSIS#include <curl/cu ...
- sql 所有数据表中 插入字段
declare @tablename varchar(200)declare @sql varchar(2000)declare cur_t cursor forselect name from sy ...
- 6.12---bug
- tensorboard在windows系统浏览器显示空白的解决
一个简单的using_tensorboard.py程序,如下: #using_tensorboard.py import tensorflow as tf a = tf.constant(10,nam ...
- 求助:可以使用任何编程工具做成一个控件或组件,使得在VB中能调用并得到摄像头的参数及图片。
请看下网址上的这个问题,看是否有解决的方式http://www.educity.cn/wenda/338634.html
- poi获取word批注
package test; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExcept ...
- java多线程之内存的可见性介绍(备用1)
(仅供参考) a.共享变量的可见能够一定程度保证线程安全,共享变量不可见导致数据不够准确,出现各种各样的问题,导致线程不安全. b.不同线程之间无法直接访问其他线程工作内存中的变量. 1.可见性 2. ...