Probabilistic and Deterministic Primality Testing in Scheme
The first algorithm most programmers meet is the naïve trial-division method. After skipping the even numbers and stopping at √n, the code looks like this: (define (naive-prime? k) (cond [(= k 2) #t] [(even? k) #f] [else (trial-loop k 3 (ceiling (sqrt k)))])) (define (trial-loop n d limit) (cond [(&...