안녕하세요.

이번에는 문제 20번을 풀어보겠습니다.

 

Factorial digit sum

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!

 

Solved

1
2
3
4
5
6
7
8
9
10
11
12
13
def fac(n):
    if(n==1):
        return 1
    else:
        return n*fac(n-1)
 
def facSum(n):
    facResult=fac(n)
    facResult=str(facResult)
    result=0
    for i in facResult:
        result+=int(i)
    return str(result)
cs

결과는 직접 확인해 보세요 ~!

+ Recent posts