Project Euler #20: Factorial digit sum

  • + 0 comments

    Python

    def factorial(n):
        if n == 0 or n == 1:
            return 1
        else:
            resultado = n * factorial(n - 1)
            return resultado
    
    def run():
        n = int(input())
        f = factorial(n)
        
        fs = str(f)
        s = 0
        for e in fs:
            s += int(e)
        print(s)
        
    for _ in range(int(input())):
        run()