Есть такая программа: http://code.google.com/p/jngmisc/source/browse/clojure/primes/
Я правильно понял, что первый миллион простых чисел: http://code.google.com/p/jngmisc/source/browse/clojure/primes/primes_10%5E6.txt проверяется за 29 секунд?
$ time clojure primes.clj
"Elapsed time: 28817.209751 msecs"
15485867
"Elapsed time: 94.50152 msecs"
15485867
real 0m29.706s
user 0m34.330s
sys 0m0.380s
Текст программы:
;;;; example macro usage with primes
(defn divides? [candidate-divisor dividend]
(zero? (rem dividend candidate-divisor)))
(defn prime? [num]
(when (> num 1)
(every? (fn [x] (not (divides? x num)))
(range 2 (inc (int (Math/sqrt num)))))))
(defn primes-from [number]
(filter prime? (iterate inc number)))
(defn primes-in-range [start end]
(for [x (primes-from start) :while (<= x end)] x))
(defmacro do-primes [var start end & body]
`(doseq [~var (primes-in-range ~start ~end)] ~@body))
;; example use
;(do-primes i 100 200
; (print (format "%d " i)))
;(println)
(defn lazy-primes []
(letfn [(enqueue [sieve n step]
(let [m (+ n step)]
(if (sieve m)
(recur sieve m step)
(assoc sieve m step))))
(next-sieve [sieve candidate]
(if-let [step (sieve candidate)]
(-> sieve
(dissoc candidate)
(enqueue candidate step))
(enqueue sieve candidate (+ candidate candidate))))
(next-primes [sieve candidate]
(if (sieve candidate)
(recur (next-sieve sieve candidate) (+ candidate 2))
(cons candidate
(lazy-seq (next-primes (next-sieve sieve candidate)
(+ candidate 2))))))]
(cons 2 (lazy-seq (next-primes {} 3)))))
(def lazy-primes (memoize lazy-primes))
(println (time (nth (lazy-primes) 1E6)))
(println (time (nth (lazy-primes) 1E6)))