1.27 Exercise 1.27

Here is a procedure to test for congruence for a number n with every integer 1 <= a <= n - 1:

(define (congruence-test num)
  (define (loop current)
    (cond ((= current num) #t)
          ((not (= (expmod current num num) current)) #f)
          (else (loop (+ current 1)))))
  (loop 1))

It is trivial to verify that this procedure returns true for the given Carmichael numbers.