about summary refs log tree commit diff
path: root/others/volume1/112.scm
blob: c03bfdc933379fe78e25eea72aa767266c9a7ef2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
(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))))