fork download
  1. ; curious numbers
  2.  
  3. (define (expm b e m)
  4. (define (m* x y) (modulo (* x y) m))
  5. (cond ((zero? e) 1)
  6. ((even? e) (expm (m* b b) (/ e 2) m))
  7. (else (m* b (expm (m* b b) (/ (- e 1) 2) m)))))
  8.  
  9. (define (curious n)
  10. (let ((xs (list 1)))
  11. (do ((i 1 (+ i 1))) ((= i n) (apply + xs))
  12. (let* ((x (expm 5 (expt 2 i) (expt 10 i)))
  13. (y (- (expt 10 i) x -1)))
  14. (display i) (display ": ")
  15. (display x) (display " ")
  16. (display y) (newline)
  17. (when (not (member x xs))
  18. (set! xs (cons x xs)))
  19. (when (not (member y xs))
  20. (set! xs (cons y xs)))))))
  21.  
  22. (display (curious 20)) (newline)
Success #stdin #stdout 0.04s 8808KB
stdin
Standard input is empty
stdout
1: 5 6
2: 25 76
3: 625 376
4: 625 9376
5: 90625 9376
6: 890625 109376
7: 2890625 7109376
8: 12890625 87109376
9: 212890625 787109376
10: 8212890625 1787109376
11: 18212890625 81787109376
12: 918212890625 81787109376
13: 9918212890625 81787109376
14: 59918212890625 40081787109376
15: 259918212890625 740081787109376
16: 6259918212890625 3740081787109376
17: 56259918212890625 43740081787109376
18: 256259918212890625 743740081787109376
19: 2256259918212890625 7743740081787109376
11111110947536882377