Topic from Project Euler 20th: https://projecteuler.net/problem=20
"Project euler:problem 20:factorial Digit sumn! means NX (n? 1) x...x3x2x1for example, 10! = 10x9x...x3x2x1 = 3628800,and The sum of the digits in the number 10! IS3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.Find The sum of the digits in the number 100! answer:648 "n = 100FAC = 1 #初始化阶乘结果while n >= 1: FAC *= n n = # extract each number of factorial results, form a list lstlst = [Int (i) for I In STR (FAC)]res = 0 #初始化相加结果for i in range (len (LST)): res + = Lst[i]print (res)
The problem is also easy, starters figure out the result of factorial 100, and then add each number of the results.
I think, should be to practice the recursive factorial, but I think the loop is also very convenient ah, is very annoying recursive function, always remember the wording, alas ...
Python Exercises 047:project Euler 020: The sum of the numbers of factorial results