invmod.md (937B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 2 3 # Function invmod 4 5 Calculate the (modular) multiplicative inverse of a modulo b. Solution to the equation `ax ≣ 1 (mod b)` 6 See https://en.wikipedia.org/wiki/Modular_multiplicative_inverse. 7 8 9 ## Syntax 10 11 ```js 12 math.invmod(a, b) 13 ``` 14 15 ### Parameters 16 17 Parameter | Type | Description 18 --------- | ---- | ----------- 19 `a` | number | BigNumber | An integer number 20 `b` | number | BigNumber | An integer number 21 22 ### Returns 23 24 Type | Description 25 ---- | ----------- 26 number | BigNumber | Returns an integer number where `invmod(a,b)*a ≣ 1 (mod b)` 27 28 29 ### Throws 30 31 Type | Description 32 ---- | ----------- 33 34 35 ## Examples 36 37 ```js 38 math.invmod(8, 12) // returns NaN 39 math.invmod(7, 13) // return 2 40 math.invmod(15151, 15122) // returns 10429 41 ``` 42 43 44 ## See also 45 46 [gcd](gcd.md), 47 [xgcd](xgcd.md)