Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as OCaml by andre ( 19 years ago )
open Bigarray
let rec is_prime n i primes =
let limit = sqrt (float_of_int n) in
let p = primes.{i} in
if n mod p = 0 then false
else if float_of_int p > limit then true
else is_prime n (i + 1) primes
let primes lim =
let res = Array1.create int c_layout (lim / 2) in
let rec primes' n i = match n with
| x when x = lim + 1 -> res
| x -> if is_prime x 0 res then begin
res.{i} <- x;
primes' (n + 1) (i + 1)
end else
primes' (n + 1) i
in res.{0} <-2;
primes' 3 1
let _ = primes (int_of_string Sys.argv.(1))
Revise this Paste