From 7ebfa64719d4ac86b30075c65f21eafe9097853e Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Wed, 22 Feb 2017 14:51:37 +0700 Subject: Updare README.md --- others/volume1/112.scm | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 others/volume1/112.scm (limited to 'others/volume1/112.scm') diff --git a/others/volume1/112.scm b/others/volume1/112.scm new file mode 100644 index 0000000..c03bfdc --- /dev/null +++ b/others/volume1/112.scm @@ -0,0 +1,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)))) -- cgit 1.4.1