(define (sqr x) (* x x)) (define (distance n) (let distance-iter ((hi (inexact->exact (truncate (sqrt n)))) (i 2)) (cond ((= n 1) 0) ((= i hi) 1) ((= (remainder n i) 0) (begin (set! n (quotient n i)) (+ (distance-iter hi i) 1))) (else (distance-iter hi (+ i 1)))))) (let loop ((a (read)) (b (read))) (unless (eof-object? a) (format #t "~a\n" (distance (quotient (* a b) (sqr (gcd a b))))) (loop (read) (read))))