let search_prime_num n = let arr = Array.make (n - 1) true in let rec search_prime_num' i = if i <= n then ( if arr.(i - 2) then ( let rec mark_comp_num j = let k = i * j in if k <= n then ( if arr.(k - 2) then arr.(k - 2) <- false; mark_comp_num (j + 1) ) in mark_comp_num 2 ); search_prime_num' (i + 1) ) in search_prime_num' 2; arr let sum_primes arr = let len_arr = Array.length arr in let rec sum_primes' i result = if i >= len_arr then result else let result' = match arr.(i) with | true -> result + i + 2 | false -> result in sum_primes' (i + 1) result' in sum_primes' 0 0 let () = let n = read_line () |> int_of_string in search_prime_num n |> sum_primes |> Printf.printf "%d\n"