何かを書き留める何か

数学や読んだ本について書く何かです。最近は社会人として生き残りの術を学ぶ日々です。

Project Euler Problem 20

n! means n × (n − 1) × ... × 3 × 2 × 1

For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!

http://projecteuler.net/problem=20

 

100の階乗の桁の和を求める問題。

これはSageによるソースである。

 >|python|
 sum(map(int,str(factorial(100))))
 ||<

 factorial(100)で100!を計算し、文字列に変換した後、桁ごとに整数へ変換し、和を求める。「桁の和」を求めるのにsum(map(int,str( *** ))) という操作をしているが早い方法は存在するだろうか。