Gauss Modular Inverse Algorithm

In the box below, set p to the modulus (some moduli with small factors will fail; primes will always work), and set a to the residue you wish to invert.