Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let rec arr_exists p arr b e =
- if b >= e
- then false
- else if p arr.(b)
- then true
- else arr_exists p arr (b + 1) e
- let n_primes n =
- let rec gather c x ps =
- if c == n
- then ps
- else if arr_exists (fun y -> x mod y = 0) ps 0 c
- then gather c (x + 2) ps
- else (ps.(c) <- x; gather (c + 1) (x + 2) ps)
- in gather 1 5 (Array.make n 2) ;;
- print_int (n_primes 100000).(99999)
Advertisement
Add Comment
Please, Sign In to add comment