Batch modular inversion

ID: batch-modular-inversion

For invertible residue classes , all their modular inverses can be recovered with one inversion and a linear number of multiplications. Store prefix products , invert once, and sweep backward: if the current inverse is , then and . The same construction works in any commutative group.

New to topics? Read the docs here!