Check Strong Number

Check whether a number is a strong number (sum of factorials of digits).

PythonBeginner
Python
# Program to check strong number

import math

num = int(input("Enter an integer: "))

total = 0
temp = num
while temp > 0:
    digit = temp % 10
    total += math.factorial(digit)
    temp //= 10

if total == num:
    print(num, "is a strong number")
else:
    print(num, "is not a strong number")

Output

Enter an integer: 145
145 is a strong number

A strong number equals the sum of factorials of its digits (e.g., 145 = 1! + 4! + 5!). We extract digits with modulo and integer division, summing factorials.