➗ Modular Arithmetic
Modular inverse, power and GCD with big integers.
Notes
The inverse exists only when gcd(a, n) = 1; it is found with the extended Euclidean algorithm, whose steps are listed. Powers use square-and-multiply. Square roots modulo a prime use Tonelli–Shanks (fast path when p ≡ 3 mod 4, as for secp256k1); only half of the nonzero values have one. All arithmetic uses exact big integers.