(define (next-odd n)
(if (odd? n)
(+ 2 n)
(+ 1 n)))
(define (smallest-divisor n)
(find-divisor n 2))
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? n test-divisor) test-divisor)
(else (find-divisor n (+ test-divisor 1)))))
(define (divides? a b)
(= (remainder a b) 0))
(define (prime? n)
(= n (smallest-divisor n)))
(define (square x)
(* x x))
(define (continue-primes n count)
(cond ((= count 0) (display "are primes"))
((prime? n) (display n)
(newline)
(continue-primes (next-odd n) (- count 1)))
(else (continue-primes (next-odd n) count))))
(continue-primes 1000 10)
转载于:https://www.cnblogs.com/R4mble/p/7892465.html
相关资源:JAVA上百实例源码以及开源项目