2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
14
Task/Arithmetic-Rational/OCaml/arithmetic-rational-5.ocaml
Normal file
14
Task/Arithmetic-Rational/OCaml/arithmetic-rational-5.ocaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(* use the module to calculate perfect numbers *)
|
||||
let () =
|
||||
for i = 2 to 1 lsl 19 do
|
||||
let sum = ref (Frac.frac 1 i) in
|
||||
for factor = 2 to truncate (sqrt (float i)) do
|
||||
if i mod factor = 0 then
|
||||
Frac.(
|
||||
sum := !sum +/ frac 1 factor +/ frac 1 (i / factor)
|
||||
)
|
||||
done;
|
||||
if Frac.is_int !sum then
|
||||
Printf.printf "Sum of reciprocal factors of %d = %s exactly %s\n%!"
|
||||
i (Frac.to_string !sum) (if Frac.to_string !sum = "1" then "perfect!" else "")
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue