問題1.21

199, 1999, 19999の最小除数を求めよ

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

(define (find-divisor n test-divisor)
  (cond ((> (square test-divisor) n) n)
	((divides? test-divisor n) test-divisor)
	(else (find-divisor n (+ test-divisor 1)))))

(smallest-divisor 199)
; => 199

(smallest-divisor 1999)
; => 1999

(smallest-divisor 19999)
; => 7

数って不思議だなあ。