Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Deceptive-numbers/OCaml/deceptive-numbers.ocaml
Normal file
17
Task/Deceptive-numbers/OCaml/deceptive-numbers.ocaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
let modpow m =
|
||||
let rec loop p b e =
|
||||
if e land 1 = 0
|
||||
then if e = 0 then p else loop p (b * b mod m) (e lsr 1)
|
||||
else loop (p * b mod m) (b * b mod m) (e lsr 1)
|
||||
in loop 1
|
||||
|
||||
let is_deceptive n =
|
||||
let rec loop x =
|
||||
x * x <= n && (n mod x = 0 || n mod (x + 4) = 0 || loop (x + 6))
|
||||
in
|
||||
n land 1 <> 0 && n mod 3 <> 0 && n mod 5 <> 0 && loop 7 &&
|
||||
modpow n 10 (pred n) = 1
|
||||
|
||||
let () =
|
||||
Seq.(ints 49 |> filter is_deceptive |> take 500
|
||||
|> iter (Printf.printf " %u%!")) |> print_newline
|
||||
Loading…
Add table
Add a link
Reference in a new issue