Solution to SICP Exercise 1.27

Solution to Exercise 1.27:

Here is the procedure for testing whether a number is a Charmichael number:

(define (congruent? n a)
(= (expmod a n n) a))

(define (carmichael? n)
(define (iter i)
(cond ((= i 0) #t)
((congruent? n i) (iter (- i 1)))
(else #f)))
(iter (- n 1)))

Advertisements