sicp 1.23

代码如下:

 

(define (smallest-divisor n)
  (find-divisor n 2))

(define (find-divisor n test-divisor)
  (cond ((> (square test-divisor) n) n)
        ((= (remainder n test-divisor) 0) test-divisor)
        (else (find-divisor n (next test-divisor)))))

(define (square x)
  (* x x))

(define (next test-divisor)
  (if (= test-divisor 2)
      3
      (+ test-divisor 2)))
 

你可能感兴趣的:(SICP)