UVA 10692 Huge Mods(指数循环节)】的更多相关文章

指数循环节,由于a ^x = a ^(x % m + phi(m)) (mod m)仅在x >= phi(m)时成立,故应注意要判断 //by:Gavin http://www.cnblogs.com/IMGavin/ //指数循环节 递归处理 #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<string> #include&l…
题目链接:uva 10692 - Huge Mods 题目大意:给出一个数的次方形式,就它模掉M的值. 解题思路:依据剩余系的性质,最后一定是行成周期的,所以就有ab=abmod(phi[M])+phi[M](phi[M]为M的欧拉函数),这样就能够依据递归去求解. #include <cstdio> #include <cstring> #include <cmath> const int maxn = 15; int A[maxn], k; int pow_mod…
vjudge上题目链接:Huge Mods 附上截图: 题意不难理解,因为指数的范围太大,所以我就想是不是需要用求幂大法: AB % C = AB % phi(C) + phi(C) % C ( B > phi(C) ) 呢?后来发现确实需要用到,而且因为它有很多重指数,所以需要 dfs,深搜到最后一层后才返回,每次向上一层返回用求幂公式处理好的指数,然后本层用同样的原理去处理好当前层取模的值,并向上一层返回.欧拉函数预处理即可,这题的结束也有点卡人,我是用输入挂来处理的. #include<…
Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2272    Accepted Submission(s): 536 Problem Description Assume that f(0) = 1 and 0^0=1. f(n) = (n%10)^f(n/10) for all n bigger than ze…
题意: 询问有多少数\(n\)满足\(n^{n!}\equiv b\mod p \land\ n\in[1,M]\),数据范围:\(M\leq2^{64}-1,p\leq1e5\) 思路: 这题显然要用欧拉降幂,\(n!\)小于\(\varphi(p)\)的直接暴力算,\(n!\neq 0\mod \varphi(p)\)也直接暴力. \(n!\equiv 0\mod \varphi(p)\)显然这时质数恒为\(\varphi(p)\),由鸽笼定理得: 当\(x\)是常数时,\(1^x,2^x,…
Mathematician QSC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description QSC dream of becoming a mathematician, he believes that everything in this world has a mathematical law. Through unremitting e…
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 ex…
phi(c)为欧拉函数, 欧拉定理 : 对于互质的正整数 a 和 n ,有 aφ(n)  ≡ 1 mod n  . A^x = A^(x % Phi(C) + Phi(C)) (mod C) (x >= phi(C))…
证明:https://www.cnblogs.com/maijing/p/5046628.html 注意使用条件(B的范围) 例题: FZU1759 HDU2837 ZOJ1674 HDU4335…
题意: 已知\(f(0)=1,f(n)=(n\%10)^{f(n/10)}\),求\(f(n)\mod m\) 思路: 由扩展欧拉定理可知:当\(b>=m\)时,\(a^b\equiv a^{b\%\varphi(m)+\varphi(m)}\mod m\),那么我们可以通过这个式子直接去递归求解. 在递归的时候每次给下一个的模数都是\(phi(mod)\),那么我们求出来之后,怎么知道要不要再加\(phi(m)\)? 我们可以在每次返回的时候用一个特殊的快速幂返回正确的值.然后每次特判返回值的…