simple-squiggle/node_modules/mathjs/docs/reference/functions/invmod.md

937 B

Function invmod

Calculate the (modular) multiplicative inverse of a modulo b. Solution to the equation ax ≣ 1 (mod b) See https://en.wikipedia.org/wiki/Modular_multiplicative_inverse.

Syntax

math.invmod(a, b)

Parameters

Parameter Type Description
a number | BigNumber An integer number
b number | BigNumber An integer number

Returns

Type Description
number | BigNumber Returns an integer number where invmod(a,b)*a ≣ 1 (mod b)

Throws

Type Description

Examples

math.invmod(8, 12)             // returns NaN
math.invmod(7, 13)             // return 2
math.invmod(15151, 15122)      // returns 10429

See also

gcd, xgcd