#open "graphics";; open_graph " 1001x1001+10+10";; let eratosthene = function n -> let crible = make_vect (n+1) true and r = int_of_float(sqrt(float_of_int n)) and compte = ref 0 in begin for i = 2 to r do if crible.(i) then (* Si i n'a pas été rayé (il est premier) *) begin (* on raye tous les multiples de i *) (* print_string("je raye les multiples de "); print_int(i); print_newline(); *) let j = ref (i * i) (* à partir de i^2 *) and pasfini = ref true in while !pasfini do crible.(!j) <- false; (* print_int(i); print_string(" "); *) compte := !compte + 1; j := !j + i; pasfini := (n >= !j); (* et ce jusqu'à ce que j *) done; (* soit supérieur à n *) (* print_newline(); *) end done; crible; end;; let ulam () = let u = ref 500 and v = ref 500 and n = ref 1 and crible = eratosthene 1002001 in for i = 1 to 500 do u := !u + 1; n := !n + 1; if crible.(!n) then plot !u !v; for j = 1 to (2 * i - 1) do n := !n + 1; v := !v + 1; if crible.(!n) then plot !u !v; done; for j = 1 to (2 * i) do n := !n + 1; u := !u - 1; if crible.(!n) then plot !u !v; done; for j = 1 to (2 * i) do n := !n + 1; v := !v - 1; if crible.(!n) then plot !u !v; done; for j = 1 to (2 * i) do n := !n + 1; u := !u + 1; if crible.(!n) then plot !u !v; done; done;; ulam ();; close_graph ();;