There is always a WAY.

—

.

(defunsum-of-squares(x y &key(a 1)(b 1))(+(* a x x)(* b y y)))(deftypecandidate()'(simple-arrayboolean(*)))(defmacroget-sieve-function(a b mod-results)`(lambda(x y)(let*((n(sum-of-squares x y :a ,a :b ,b))(r(modn 12)))(when(and(<= n limit)(not(null(memberr ,mod-results))))(setf(arefcandidates n)(not(arefcandidates n)))))))(defunget-atkin-prime-candidates-map(limit)(let*((lmt(isqrtlimit))(candidates(make-array(1+ limit):initial-elementnil))(stage1(get-sieve-function 4 1 '(1 5)))(stage2(get-sieve-function 3 1 '(7)))(stage3(get-sieve-function 3 -1 '(11))))(declare(typecandidate candidates))(declare(optimize(speed3)))(loopfor x from 1 to lmtdo(loopfor y from 1 to lmtdo(progn(funcallstage1 x y)(funcallstage2 x y)(when(> x y)(funcallstage3 x y)))))candidates))(defunatkin-sieve-map(candidates)(let((len(lengthcandidates)))(loopfor i from 1 to(1- len)when(arefcandidates i)do(loopfor j from 1 for n =(* j i i)while(< n len)do(setf(arefcandidates n)nil))))(setf(arefcandidates 2)T)(setf(arefcandidates 3)T)candidates)(defuneratosthene-sieve-map(limit)(let((candidates(make-array(1+ limit):initial-elementT)))(declare(typecandidate candidates))(declare(optimize(speed3)))(progn(setf(arefcandidates 0)nil)(setf(arefcandidates 1)nil))(loopfor i from 2 to limitwhen(arefcandidates i)do(loopfor j from(+ i i)to limit by iwhen(arefcandidates j)do(setf(arefcandidates j)nil)))candidates));; This is free software released ;; into the public domain. ;; ;; ykm(defunget-primes(limit &key(generator :eratosthene))(let((candidates(casegenerator(:atkin(atkin-sieve-map(get-atkin-prime-candidates-map limit)))(:eratosthene(eratosthene-sieve-map limit))(otherwise(error"not valid type (:atkin :eratosthene)")))))(declare(typecandidate candidates))(loopfor i from 0 to(1-(lengthcandidates))when(arefcandidates i)collect i)))(formatt"soe: ~d "(time(length(get-primes 12345678))))(formatt"soa: ~d "(time(length(get-primes 12345678 :generator :atkin))))(defmacrolog10(x)`(/(log,x)(log10)))

.

— Me@2022.09.06 03:24:36 PM

.

.

2022.09.06 Tuesday (c) All rights reserved by ACHK

You must be logged in to post a comment.