(define (int x) (inexact->exact (floor x))) (define (newton a n) (define (newton-iter a n x x-) (if (<= (abs (- x x-)) 1) (if (> (expt x n) a) (- x 1) x) (let ((tmp (expt x- (- n 1)))) (newton-iter a n x- (- x- (int (/ (- (* tmp x-) a) (* tmp n)))))))) (newton-iter a n 0 (int (sqrt a)))) (define (numsum x) (define (numsum-iter x a) (if (= x 0) a (numsum-iter (int (/ x 10)) (+ a (modulo x 10))))) (numsum-iter x 0)) (define (main end) (define (main-iter i end value) (if (> i end) value (if (= (expt (int (sqrt i)) 2) i) (main-iter (+ i 1) end value) (main-iter (+ i 1) end (+ value (numsum (newton (* i (expt 100 99)) 2))))))) (define (main-tt i end a) (display (list (- i 1) a)) (newline) (if (> i end) '() (main-tt (+ i 1) end (main-iter 1 i 0)))) (main-iter 2 end 0)) (display (main 10)) (newline)