English

On the Inversion Modulo a Power of an Integer

Data Structures and Algorithms 2026-03-13 v4

Abstract

Recently, Ko\c{c} proposed a neat and efficient algorithm for computing x=a1(modpk) x = a^{-1} \pmod {p^k} for a prime pp based on the exact solution of linear equations using pp-adic expansions. The algorithm requires only addition and right shift per step. In the first part of this paper, we design an algorithm that computes x=a1(modnk) x = a^{-1} \pmod {n^k} for any integers a,n>1a, n>1 with gcd(a,n)=1\gcd(a, n)=1. The algorithm has a motivation from the schoolbook multiplication and achieves both efficiency and generality. The greater flexibility of our algorithm is explored by utilizing the built-in arithmetic of computer architecture, e.g., n=264n=2^{64}, and experimental results show significant improvements. This paper also contains some results on modular inverse based on an alternative proof of correctness of Ko\c{c} algorithm. For the computation of modular inverses when the modulus is a special power of a prime pp (i.e., of the form p2sp^{2^s}), an efficient algorithm was developed by Dumas and later improved by Hurchalla. These methods are based on Hensel lifting and perform particularly well when p=2p=2 and 2s2^s matches the native bit width of a computer. In the second part of the paper, we present a generalization of these methods to moduli of the form n2sn^{2^s} for any integer n>1n>1. The derivation of our algorithm follows from a simple algebraic manipulation.

Keywords

Cite

@article{arxiv.2506.02491,
  title  = {On the Inversion Modulo a Power of an Integer},
  author = {Guangwu Xu and Yunxiao Tian and Bingxin Yang},
  journal= {arXiv preprint arXiv:2506.02491},
  year   = {2026}
}
R2 v1 2026-07-01T02:56:02.248Z