Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Modular-inverse/F-Sharp/modular-inverse.fs
Normal file
11
Task/Modular-inverse/F-Sharp/modular-inverse.fs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// Calculate the inverse of a (mod m)
|
||||
// See here for eea specs:
|
||||
// https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
|
||||
let modInv m a =
|
||||
let rec eea t t' r r' =
|
||||
match r' with
|
||||
| 0 -> t
|
||||
| _ ->
|
||||
let div = r/r'
|
||||
eea t' (t - div * t') r' (r - div * r')
|
||||
(m + eea 0 1 m a) % m
|
||||
Loading…
Add table
Add a link
Reference in a new issue