Computing Modular Inverses: Templates and an Application in Random Stacks
The modular inverse of an integer (a) under modulus (p) is an integer (x) such that [ a \cdot x \equiv 1 \pmod p. ] When (p) is a prime, Fermat’s little theorem provides a direct way to compute (x). The theorem states (a^{p-1} \equiv 1 \pmod p), therefore [ a \cdot x \equiv a^{p-1} \pmod p \quad\Rig...