---
title: "SICP 1.21 答案"
author: "t0uch"
date: "2009-11-10T16:13:01Z"
tags: []
slug: "sicp-1-21"
draft: false
lastmod: "2009-11-10T16:13:38Z"
id: 513722
url: "https://t0uch.iteye.com/blog/513722"
---

很简单


```Scheme
(define (smallest-divisor n)
  (find-divisor n 2))
(define (find-divisor n test-divisor)
  (cond ((> (* test-divisor test-divisor) n) n)
        ((divides? test-divisor n) test-divisor)
        (else (find-divisor n (+ test-divisor 1)))))
(define (divides? a b)
  (= (remainder b a) 0))

(smallest-divisor 199)   ;199
(smallest-divisor 1999)  ;1999
(smallest-divisor 19999) ;7
```