Code Review
Compare your solutions
#| Для этого упражнения нет проверок.
Любое решение будет считаться успешным ответом. |#
(define (square x) (* x x))
(define (expmod base exp m)
(cond ((= exp 0) 1)
((even? exp)
(remainder (square (expmod base (/ exp 2) m))
m))
(else
(remainder (* base (expmod base (- exp 1) m))
m))))
(define (timed-prime-test n)
(newline)
(display n)
(fast-prime? n (runtime)))
(define (report-prime elapsed-time)
(display " *** ")
(display elapsed-time))
(define (fast-prime? n times)
(cond ((= times 0) true)
((fermat-test n) (fast-prime? n (- times 1)))
(else false)))
(define (fermat-test n)
(define (try-it a)
(= (exmod a n n) a))
(try-it (+ 1 (random (- n 1)))))
(define (search-for-primes start end)
(if (even? start)
(search-for-primes (+ 1 start) end)
(when (< start end)
(timed-prime-test start)
(search-for-primes (+ 2 start) end))))