You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
786 B

(* OCaml version of a prime number finder
haplo@mindstab.net *)
let primes max =
let sq = ref 2 in
let sqm = ref 4 in
let cnt = ref 3 in
let m = ref 0 in
while !cnt <= !max do
let i = ref 3 in
let stop = ref false in
m := 1;
while !i <= !sq && not !stop do
m := (!cnt mod !i);
if !m = 0 then
stop := true;
i := !i + 2
done;
if not (!m = 0) then
(print_int(!cnt);
print_newline());
if !cnt >= !sqm then
(sq := !sq+1; sqm := !sq * !sq);
cnt := !cnt + 2
done;;
let max = ref (int_of_string Sys.argv.(1)) in
if !max < 1 then (print_string("Invalid Max Num\n"); exit(1););
primes(max);