[Python] How to compute the sum of the factorials of the digits of n?

Discussão em 'Python' iniciado por Stack, Maio 23, 2025.

  1. Stack

    Stack Membro Participativo

    I approached this problem as shown below, yet the answer comes ridiculously large! How do I fix this?

    n = int(input())
    s = 0
    ld = 0
    f = 1

    while n != 0:
    ld = n % 10
    for i in range(1, ld + 1):
    f = f * i
    s = s + f
    n = n // 10

    print(s)

    Continue reading...

Compartilhe esta Página