SICP习题 1.23(素数查找的去偶数优化)

mac2022-06-30  28

(define (next n) (if (= n 2) 3 (+ n 2))) (define (find-divisor n test-divisor) (cond ((> (square test-divisor) n) n) ((divides? n test-divisor) test-divisor) (else (find-divisor n (next test-divisor))))) (define (smallest-divisor n) (find-divisor n 2)) (define (divides? a b) (= (remainder a b) 0)) (define (prime? n) (= n (smallest-divisor n))) (define (square x) (* x x)) (smallest-divisor 177)

  

转载于:https://www.cnblogs.com/R4mble/p/7892524.html

相关资源:SICP 习题答案
最新回复(0)