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