-
Notifications
You must be signed in to change notification settings - Fork 0
/
pe023.ml
28 lines (25 loc) · 810 Bytes
/
pe023.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
open Core.Std
let sum_divisors_upto upto =
Common.generic_sieve upto
~init:(fun ~fill ~set:_ -> fill 1)
~update:(fun orig _ _ sum -> sum + orig)
let find_minimum_non_sum upto =
let sum_divisors = sum_divisors_upto upto in
let is_abundant n = sum_divisors n > n in
let rec iter acc cur =
if cur > upto then
acc
else
let rec iteri i =
if i > cur - i then
false
else
if is_abundant i && is_abundant (cur - i) then
true
else
iteri (i + 1)
in
iter (acc + (if iteri 1 then 0 else cur)) (cur + 1)
in
iter 0 0
let () = find_minimum_non_sum 28_123 |> Printf.printf "%d\n"