Euler’s Problem: 20

n! means n * (n-1) * … * 3 * 2 * 1

Find the sum of the dig­its in the num­ber 100!

#!/usr/bin/env python

t = 1
x = 0

for i in range(1,101):
    t = t * i

for i in str(t):
    x = x + int(i)

print x
/home/umgeher/war/hg/euler/python> time python 20.py
648

Time spent in user mode   (CPU seconds) : 0.016s
Time spent in kernel mode (CPU seconds) : 0.008s
Total time                              : 0:00.02s
CPU utilisation (percentage)            : 50.0%
Times the process was swapped           : 0
Times of major page faults              : 0
Times of minor page faults              : 649
/home/umgeher/war/hg/euler/python>

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>