Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
A number n is abundant if its proper-divisor sum exceeds n. Reuses
the trial-division div_sum helper:
let count_abundant n =
let c = ref 0 in
for i = 12 to n - 1 do
if div_sum i > i then c := !c + 1
done;
!c
count_abundant 100 = 21
Abundant numbers under 100, starting at 12, 18, 20, 24, 30, 36, 40,
42, 48, 54, 56, 60, 66, 70, 72, 78, 80, 84, 88, 90, 96 -> 21.
Companion to euler21_small.ml (amicable). The classification:
perfect: d(n) = n (e.g. 6, 28)
abundant: d(n) > n (e.g. 12, 18)
deficient:d(n) < n (everything else)
124 baseline programs total.
24 lines
389 B
OCaml
24 lines
389 B
OCaml
let div_sum n =
|
|
let s = ref 1 in
|
|
let i = ref 2 in
|
|
while !i * !i <= n do
|
|
if n mod !i = 0 then begin
|
|
s := !s + !i;
|
|
let q = n / !i in
|
|
if q <> !i then s := !s + q
|
|
end;
|
|
i := !i + 1
|
|
done;
|
|
if n = 1 then 0 else !s
|
|
|
|
let count_abundant n =
|
|
let c = ref 0 in
|
|
for i = 12 to n - 1 do
|
|
if div_sum i > i then c := !c + 1
|
|
done;
|
|
!c
|
|
|
|
;;
|
|
|
|
count_abundant 100
|