Added powmod in utility and PowerMod in the sintax and semantics of MiniImp

This commit is contained in:
elvis
2024-10-07 14:13:28 +02:00
parent f40428251a
commit 27c82f6357
5 changed files with 19 additions and 2 deletions

View File

@ -4,3 +4,10 @@ let rec pow a = function
| 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