# 练习1.23-练习1.30

1.练习1.23

(define (find-divisor-better n a)
(cond ((> (square a) n) n)
((divides?-better n a) a)
(else (find-divisor-better n (next-2 a)))))

(define (next-2 n)
(if (= 2 n)
(+ 1 n)
(+ 2 n)))
(define (find-min-prime-since-better n start-time number)
(cond ((= number 0) (display-info start-time (real-time-clock)))
((prime? n) (begin
(format #t "~S~%" n)
(find-min-prime-since-better (+ n (next-plus n)) start-time (- number 1))))
(else (find-min-prime-since-better (+ n (next-plus n)) start-time number)))
#f)
(define (next-plus n)
(if (even? n)
1
2))

2.练习1.24

3.练习1.25

4.练习1.26

5.练习1.27

(define (try-it a n)
(= (expmod a n n) a))

(define (carmichael-test n number)
(cond ((= number 0) true)
((try-it number n) (carmichael-test n (- number 1)))
(else false)))

(define (car-prime? n)
(carmichael-text n (- n 1)))

6.练习1.28

(define (new-expmod base exp m)
(define tmpbase 100)
(cond ((= exp 0) 1)
((even? exp) (begin
(set! tmpbase (new-expmod base (/ exp 2) m))
(if (and (not (= tmpbase (- m 1)))
(not (= tmpbase 1))
(= (remainder (square tmpbase)
m) 1))
0
(remainder (square tmpbase)
m))))
(else (remainder (* base (new-expmod base (- exp 1) m))
m))))
(define (new-try-it n a)
(new-expmod a (- n 1) n))

(define (new-fermat-test n start)
(cond ((= start 1) true)
((= (new-try-it n start) 0) false)
(else (new-fermat-test n (- start 1)))))

(define (really-prime? n)
(new-fermat-test n (if (even? n)
(/ n 2)
(/ (- n 1) 2))))


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客