[back]

Perfect Numbers

Implement the function

val is_perfect : int -> bool

so that is_perfect n is true if and only if n is equal to the sum of its proper divisors.

Examples

let _ = assert (is_perfect 6)        (* 6  =  1 + 2 + 3 *)
let _ = assert (is_perfect 28)       (* 28 =  1 + 2 + 4 + 7 + 14 *)
let _ = assert (not (is_perfect 24)) (* 24 <> 1 + 2 + 3 + 4 + 6 + 8 + 12 *)