Function
src/index.ts:978nerdamer.modInv
nerdamer.modInv(a: Expression, p: Expression): ExpressionComputes the modular multiplicative inverse of a modulo p using the
extended Euclidean algorithm. That is, finds t such that a * t ≡ 1 (mod p).
throws
core!MathError If the inverse does not exist (i.e. gcd(a, p) ≠ 1).
Parameters
| Name | Type | Description |
|---|---|---|
a | Expression | The number whose modular inverse is to be calculated. |
p | Expression | The modulus (typically prime). |
Returns
Expression — The modular inverse of a mod p.
Examples
modInv(Expression.create(3), Expression.create(7)).text() // "5"
modInv(Expression.create(10), Expression.create(17)).text() // "12"