2024-10-05 18:40:45 +02:00
|
|
|
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)
|
2024-10-07 14:13:28 +02:00
|
|
|
|
|
|
|
|
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
|
2024-12-01 12:55:20 +01:00
|
|
|
|
|
|
|
|
let rec fromIntToString (alphabet: string) (x: int) : string =
|
|
|
|
|
let base = String.length alphabet in
|
|
|
|
|
if x < 0 then
|
|
|
|
|
""
|
|
|
|
|
else if x < base then
|
|
|
|
|
String.get alphabet x |> String.make 1
|
|
|
|
|
else
|
|
|
|
|
(fromIntToString (alphabet) (x/base - 1)) ^ (String.get alphabet (x mod base) |> String.make 1)
|