Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let era_sieve n =
- (* set the upper bound of numbers to check *)
- let upper = n * n in
- (* populate a list with numbers that we can record primeness of *)
- let primes = Array.create upper true in
- (* walk the numbers between 2 and the upper bound *)
- for this_num = 2 to upper do
- (* next, just iterate through the sieve *)
- (* yes, this will hit the same numbers bunches of times, but
- * this isn't about efficiency... *)
- for iterator = this_num to upper do
- let multiple = 1 in
- let next_nonprime = iterator * iterator + multiple * iterator in
- while next_nonprime < upper do
- (* well, all these numbers are certainly not prime! *)
- primes.( next_nonprime ) <- false ;
- multiple := !multiple + 1 ;
- done
- done
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement