! Copyright (C) 2009 Samuel Tardieu. ! See http://factorcode.org/license.txt for BSD license. USING: kernel kernel.private locals math math.bitwise math.functions math.order math.ranges sequences sequences.private ; IN: math.primes.erato [ sieve unmark ] each ] when ; inline : init-sieve ( n -- sieve ) 30 /i 1 + [ 255 ] B{ } replicate-as ; inline PRIVATE> :: sieve ( n -- sieve ) n integer>fixnum-strict init-sieve :> sieve sieve upper-bound >fixnum :> upper 2 upper sqrt [a,b] [ upper sieve unmark-multiples ] each sieve ; : marked-prime? ( n sieve -- ? ) 2dup upper-bound 2 swap between? [ bounds-error ] unless over { 2 3 5 } member? [ 2drop t ] [ marked-unsafe? ] if ;