Problem 20 - 100!

100の階乗

Problem 20 - PukiWiki

n × (n - 1) × ... × 3 × 2 × 1 を n! と表す。

100! の各桁の数字の合計を求めよ。

簡単。


前に作ったユーティリティを利用して、

(define (number->list n)
  (define (iter acc n)
    (let ((q (quotient n 10))
          (m (cons (modulo n 10) acc)))
         (if (zero? q)
             m
             (iter m q))))
  (iter '() n))

(apply + (number->list (apply * (iota 100 1)))) ; 648

イイネ。お、20問達成。