An Elementary Method For Fast Modular Exponentiation With Factored Modulus
Abstract: We present a fast algorithm for modular exponentiation when the factorization of the modulus is known. Let $a,n,m$ be positive integers and suppose $m$ factors canonically as $\prod_{i=1}k p_i{e_i}$. Choose integer parameters $t_i\in [1, e_i]$ for $1\le i\le k$. Then we can compute the modular exponentiation $an\pmod{m}$ in $O(\max(e_i/t_i)+\sum_{i=1}k t_i\log p_i)$ steps (i.e., modular operations). We go on to analyze this algorithm mathematically and programmatically, showing significant asymptotic improvement in specific cases. Specifically, for an infinite family of $m$ we achieve a complexity of $O(\sqrt{\log m})$ steps, much faster than the Repeated Squaring Algorithm, which has complexity $O(\log m)$. Additionally, we extend our algorithm to matrices and hence general linear recurrences. The complexity is similar; with the same setup we can exponentiate matrices in $GL_d(\mathbb{Z}/m\mathbb{Z})$ in less than $O(\max(e_i/t_i)+d2\sum_{i=1}k t_i\log p_i)$ steps. This improves Fiduccia's algorithm and the results of Bostan and Mori in the case of $\mathbb{Z}/m\mathbb{Z}$. We prove analogous results for $\mathbb{Z}/pk\mathbb{Z}$ ring extensions.
- Algorithm for fast modular exponentiation modulo exponent-heavy numbers. https://github.com/misaacs3737/modExp/, 2023. Accessed: January 17, 2024.
- Donald E. Knuth. The Art of Computer Programming, Vol. 1: Fundamental Algorithms. Addison-Wesley, Reading, Mass., third edition, 1997.
- Ivan Niven. Averages of exponents in factoring integers. Proceedings of the American Mathematical Society, 22(2):356–360, 1969.
- Sur la répartition du noyau d’un entier. Indagationes Mathematicae, 24(4):802–914, 2013. In memory of N.G. (Dick) de Bruijn (1918–2012).
- Joris Hoeven. Fast chinese remaindering in practice. pages 95–106, 11 2017.
Paper Prompts
Sign up for free to create and run prompts on this paper using GPT-5.
Top Community Prompts
Collections
Sign up for free to add this paper to one or more collections.