http://projecteuler.net/index.php?section=problems&id=29
Setは次のように使います。
let s : int Set = Set.empty let s1 = s.Add 1 let s2 = s1.Add 2 let s3 = s2.Add 1 printfn "%A" s3 // seq [1; 2]
Addすると新たにSetが作られます。使いにくいですね。
この問題の場合は、Listを作ってそれを元にSetを作ればよいでしょう。
let s = Set.ofList [1..5] printfn "%d" s.Count
let rec calc_exp n p = if n % p = 0 then let t = calc_exp (n / p) p (fst t + 1, snd t) else (0, n) let rec fac n p = if n = 1 then [] else if p * p > n then [(n, 1)] else let t = calc_exp n p if fst t > 0 then (p, fst t) :: (fac (snd t) (p + 1)) else fac n (p + 1) let rec pow n e = if e = 0 then 1 else let m = pow n (e / 2) if e % 2 = 1 then m * m * n else m * m let factorize n = fac n 2 let pow_f f e = List.map (fun x -> (fst x, (snd x) * e)) f let N = 100 let s = Set.ofList [ for f in List.map factorize [2..N] do for b in 2..N -> pow_f f b ] printfn "%d" s.Count