Files
lci/lib/utility.ml

14 lines
299 B
OCaml

let rec pow a = function
| 0 -> 1
| 1 -> a
| n ->
let b = pow a (n / 2) in
b * b * (if n mod 2 = 0 then 1 else a)
let rec powmod a d = function
| 0 -> 1
| 1 -> a mod d
| n ->
let b = (powmod a d (n / 2)) mod d in
(((b * b) mod d) * (if n mod 2 = 0 then 1 else a)) mod d