[back]

Number of Factors

Implement the function

val num_factors : int -> int

so that num_factors n is the number of prime factors of n. The behavior of the function is undefined if n is not positive.

Examples

let _ = assert (num_factors 16 = 4)   (* 16 = 2 * 2 * 2 * 2 *)
let _ = assert (num_factors 18 = 3)   (* 18 = 2 * 3 * 3 *)
let _ = assert (num_factors 19 = 1)   (* 19 is prime *)