Code Review

Compare your solutions

    #| BEGIN (Введите свое решение) |#
(define (square n)
  (* n n))

(define (remainder-check x m)
  (if (and
        (not (= 1 x))
        (not (= (- m 1) x))
        (= (remainder (square x) m) 1))
      0
      (remainder (square x) m)))

(define (expmod-check base exp m)
  (cond ((= exp 0) 1)
        ((even? exp)
         (remainder-check (expmod-check base (/ exp 2) m) m))
        (else
         (remainder 
          (* base (expmod-check base (- exp 1) m))
          m))))

(define (miller-rabin-test n)
  (define (try-it a)
    (= (expmod-check a (- n 1) n) 1))
  (try-it (+ 1 (random (- n 1)))))
#| END |#
    #| BEGIN (Введите свое решение) |#
(define (square x) (* x x)) 
  
 (define (miller-rabin-expmod base exp m) 
   (define (squaremod-with-check x) 
     (define (check-nontrivial-sqrt1 x rem-square) 
       (if (and (= rem-square 1) 
                (not (= x 1)) 
                (not (= x (- m 1)))) 
           0 
           rem-square)) 
     (check-nontrivial-sqrt1 x (remainder (square x) m))) 
   (cond [(= exp 0) 1]
         [(even? exp) (squaremod-with-check (miller-rabin-expmod base (/ exp 2) m))]
         [else (remainder (* base (miller-rabin-expmod base (- exp 1) m)) m)])) 
  
 (define (miller-rabin-test n) 
   (define (try-it a) 
     (define (check-it x) 
       (and (not (= x 0)) (= x 1))) 
     (check-it (miller-rabin-expmod a (- n 1) n))) 
   (try-it (+ 1 (random (- n 1)))))
#| END |#
    #| BEGIN (Введите свое решение) |#
(define (square n)
  (* n n))

(define (remainder-check x m)
  (if (and
        (not (= 1 x))
        (not (= (- m 1) x))
        (= (remainder (square x) m) 1))
      0
      (remainder (square x) m)))

(define (expmod-check base exp m)
  (cond ((= exp 0) 1)
        ((even? exp)
         (remainder-check (expmod-check base (/ exp 2) m) m))
        (else
         (remainder 
          (* base (expmod-check base (- exp 1) m))
          m))))

(define (miller-rabin-test n)
  (define (try-it a)
    (= (expmod-check a (- n 1) n) 1))
  (try-it (+ 1 (random (- n 1)))))
#| END |#
    #| BEGIN (Введите свое решение) |#
(define (square x) (* x x)) 
  
 (define (miller-rabin-expmod base exp m) 
   (define (squaremod-with-check x) 
     (define (check-nontrivial-sqrt1 x rem-square) 
       (if (and (= rem-square 1) 
                (not (= x 1)) 
                (not (= x (- m 1)))) 
           0 
           rem-square)) 
     (check-nontrivial-sqrt1 x (remainder (square x) m))) 
   (cond [(= exp 0) 1]
         [(even? exp) (squaremod-with-check (miller-rabin-expmod base (/ exp 2) m))]
         [else (remainder (* base (miller-rabin-expmod base (- exp 1) m)) m)])) 
  
 (define (miller-rabin-test n) 
   (define (try-it a) 
     (define (check-it x) 
       (and (not (= x 0)) (= x 1))) 
     (check-it (miller-rabin-expmod a (- n 1) n))) 
   (try-it (+ 1 (random (- n 1)))))
#| END |#