# 练习1.23-练习1.30

16 篇文章 0 订阅
15 篇文章 0 订阅

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))))


• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
01-08 664
01-06 632
01-13 625
02-07 617
01-20 617
01-20 591
01-07 590
01-22 584
01-17 566
01-23 562
01-15 558
01-10 533
01-14 491

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。